Whenever I have the headers added to mail()
, the recipient does not receive any email.
This works ok:
// The message
$message = "Line 1\r\nLine 2\r\nLine 3";
// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70, "\r\n");
// Send
mail('contact@xxx.net', 'My Subject 2', $message);
This is not ok:
// The message
$message = "Line 1\r\nLine 2\r\nLine 3";
// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70, "\r\n");
// Send with headers
mail('contact@xxx.net', 'My Subject', $message, 'From: Test <test123@yahoo.co.uk>');
Any ideas why?
EDIT:
It seems that it is caused by the @yahoo.co.uk
email addresses. It is ok with @gmail.com
!
Why!??? Is it something to with my production server??
EDIT 2:
Same thing happens even though I use PHPMailer:
// Include Composer autoloader.
require_once __DIR__ . '/vendor/autoload.php';
$mail = new PHPMailer;
$mail->setFrom('test123@yahoo.co.uk', 'Mailer');
$mail->addAddress('contact@xxx.net', 'Joe User'); // Add a recipient
$mail->addAddress('ellen@example.com'); // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
But it works ok with @gmail.com
:
$mail->setFrom('test123@gmail.com', 'Mailer');