Reputation: 4349
I'm using mail
to send e-mails from PHP. It's working fine, but now I need to use a more secure mail server.
I need to connect with the mail server using the following configuration:
smtp: "mail.newserver.com"
port: "25"
timeout: 60
auth: yes
user: name
pass: word
How should I change my code below so it works with above configuration?
$to = $SendTo;
$headers = "From: <info@---->" . "\r\n" . "X-Mailer: php";
$subject = "Website Contact : " . $uxGlobalLocation;
$body = $Bodycopy;
if (mail($to, $subject, $body, $headers)) {
header ('Location: /index.php?option');
exit();
} else {
echo("<p>Message delivery failed...</p>");
}
Upvotes: 12
Views: 36217
Reputation: 146350
The builtin mail() function does not provide any sort of authentication. You need to use a third-party library that offers SMTP authentication. Popular choices include:
You can also search for Composer packages at Packagist.
Upvotes: 8
Reputation: 4775
Actually mail function doesn't provide authentication functionality. Your have to use Mail class from Mail Pear package. See here for an example: http://email.about.com/od/emailprogrammingtips/qt/PHP_Email_SMTP_Authentication.htm
Upvotes: 12