Php mail authentication

I use mail to send email with PHP. It works fine, but now I need to use a more secure mail server.

I need to connect to the mail server using the following configuration:

 smtp: "mail.newserver.com" port: "25" timeout: 60 auth: yes user: name pass: word 

How do I change my code below to work with the 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>"); } 
+8
php
source share
2 answers

In fact, the mail function does not provide an authentication function. You need to use the Mail class from the Mail Pear package. See an example here: http://email.about.com/od/emailprogrammingtips/qt/PHP_Email_SMTP_Authentication.htm

+10
source share

The built-in mail () function does not provide any authentication. You need to use a third-party library that offers SMTP authentication. Popular options:

You can also search for Composer packages on Packagist .

+6
source share

All Articles