I have few doubts regarding the mail options in PHP.
Whatever I have read, I can not send mail from localhost without SMTP. Is it correct ?
For sending the mail from localhost using the PHP mail() function, I need to make few changes in these two files. one is 'php.ini' & another one is 'sendmail.ini'. changes like setting smtp_server, port, username & password. This option is working for me perfectly & I have sent mail using this. Just want to confirm that am I following the correct way for sending the mail from localhost ?
If I just have to send simple mails, is there any much difference between mail() function & PHPMailer ?
After changing the two ini files(php.ini & sendmail.ini), I am using the example given on 'https://github.com/PHPMailer/PHPMailer' at the end of the page, but that example is not working. I am using the same SMTP in the PHPMailer example which I have used in 'sendmail.ini', but still that is not working. But If I comment out the SMTP part in PHPMailer example, which is
/*$mail->isSMTP(); // Set mailer to use SMTP $mail->Host = 'smtp1.example.com;smtp2.example.com'; $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = '[email protected]'; // SMTP username $mail->Password = 'secret'; // SMTP password $mail->SMTPSecure = 'tls'; //Enable TLS encryption,
sslalso accepted $mail->Port = 587; */
then it is working perfectly fine. I do not know why do I have to comment out the SMTP part ?
Please help me to clear my doubts. Thanks in advance
You need to have mail server (like linux
sendmail
) to send messages. You can use your server's built-in mail post server or connect to SMTP. PHP has no built-in mail server / "postman"It's OK as far as you setup your hostname/domain/dns records properly otherwise your mail will land into junk/spam box. Read about SPF record for more info.
PHPMailer by default uses
mail()
. PHPMailer is just nice and easy interface/layer formail()
so you don't have to write complicated mail headers by yourself. In case of STMP phpmailer uses socketscheck what
echo 'Mailer Error: ' . $mail->ErrorInfo;
says