Are you still using PHP mail() function to send email on your webpage? Guess it’s time to say bye bye
Why? Because mail() function will use the webserver to send email instead of a real mail server. However, we recently found out that the recipient mail server will check the sender IP and when it notices that the sender IP is not an email server, then it will block the message and the messages will never get through to recipient mailbox. This problem seems to be applicable to some email server (recipients’) such as Yahoo, AOL and other companies.
How to solve this problem? Easy, don’t use webserver to send email, but use a real email server with SMTP. If you’re using PHP, simply download phpmailer class and send email using SMTP.
Below is the code sample that you need to write on your webpage:
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = “mail.yourdomain.com”; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = “firstname.lastname@example.org”; // SMTP username
$mail->Password = “password”; // SMTP password
$mail->From = “email@example.com”;
$mail->FromName = “Sender’s name”;
$mail->Subject = “subject here”;
$mail->Body = “message body here”;
echo “Mailer Error: ” . $mail->ErrorInfo;
echo “Message has been sent successfully.”;
That’s it You can even add more functionality such as HTML email, attachments, send to CC & BCC with simply add more properties to the mailer class and without having to worry about your mail got bounced back by some mail servers out there. Please refer to PHPMailer’s documentation for more info
And for those of you who are using wordpress then WP_Mail SMTP is the best plugin you need.