0

I am trying to send an email to user once he signs up on my localhost project, I am working on Xampp and my OS is Mac, I know this function is correct:

$to_email = "receipient@gmail.com";
$subject = "Simple Email Test via PHP";
$body = "Hi,nn This is test email send by PHP Script";
$headers = "From: sender\'s email";

if (mail($to_email, $subject, $body, $headers)) {
    echo "Email successfully sent to $to_email...";
} else {
    echo "Email sending failed...";
}

But there is something to configure in SMTP i guess? however I can't find what and where to edit on MAC, thank you in advance.

mohamad
  • 35
  • 6

1 Answers1

0

If you want to send a mail from a local server using for example XAMPP, you will need to use the mail server in order to do it.

Do something like this:

<?php
ini_set("SMTP", "aspmx.l.google.com");
ini_set("sendmail_from", "YOURMAIL@gmail.com");
$message = "The mail message was sent with the following mail setting:\r\nSMTP = aspmx.l.google.com\r\nsmtp_port = 25\r\nsendmail_from = YourMail@address.com";
$headers = "From: YOURMAIL@gmail.com";
mail("Sending@provider.com", "Testing", $message, $headers);

You will most likely need the mail account's credentials in order to send a mail.

Also, check out Sending email with PHP from an SMTP server.

Tim Anthony
  • 123
  • 8