How can I check a problem with mail being sent on my server? I run a simple test:
if(mail($to, $subject, $message)) {
echo 'Mail Sent';
}
which the test outputs the text; but, no mail ever arrives.
How can I go about tracking down the issue?
How can I check a problem with mail being sent on my server? I run a simple test:
if(mail($to, $subject, $message)) {
echo 'Mail Sent';
}
which the test outputs the text; but, no mail ever arrives.
How can I go about tracking down the issue?
To send an email you need a SMTP server (local or remote). Actually your mail function just passes the mail to your SMTP server and is this one which really send your email.
In your php.ini appears this line
sendmail_path = /usr/sbin/sendmail -t -i
You should be aware if you use that configuration parameter (from manual):
If set, smtp, smtp_port and sendmail_from are ignored and the specified command is executed.
But the most important thing here is you just uninstall sendmail so you can expect your mail goes nowhere. I know sendmail was giving you some problems, possibly configuration problems, but now your php.ini configuration is wrong.
How to solve it?
Start removing the sendmail_path parameter from the php.ini.
Install a simple to configure SMTP server like postfix.
Verify postfix is listening at port 22:
netstat -lnt
Try to send a mail from your php mail() function
Verify your mail has been sent correctly (check your /var/log/mail.log or /var/log/mail/mail.log files)
You also can verify the mail is not in the postfix queue:
postqueue -f
I Finally got a laaaaarge smile on my face. Working together with @DaveRandom, He helped me come up with these codes:
NOTE: The code bellow uses PHPMailer
<?php
$senderName = 'Erick Best'; //Enter the sender name
$username = 'erickbestism@yahoo.com'; //Enter your Email
$password = 'passwordHere';// Enter the Password
$recipients = array(
'erickbestism@gmail.com' => 'Erick Best',
'erickbestism@yahoo.com' => 'Yahoo User',
);
///That's all you need to do
//No need to edit bellow
require '../PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer();
// Set up SMTP
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.mail.yahoo.com";
$mail->Port = 587; // we changed this from 486
$mail->Username = $username;
$mail->Password = $password;
// Build the message
$mail->Subject = 'PHPMailer mail() test';
$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
$mail->AltBody = 'This is a plain-text message body';
$mail->addAttachment('images/phpmailer_mini.gif');
// Set the from/to
$mail->setFrom($username, $senderName);
foreach ($recipients as $address => $name) {
$mail->addAddress($address, $name);
}
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
And this WORKED like VOODOO!... It sent mails to any provider. Including **YAHOO**
Hope it helps someone!
Have you tried the mailq command to see if there are errors? Here's an answer to a similar question on ServerFault with more detail.
You can get around the MX lookup by adding a short entry into your sendmail /etc/mail/mailertable
file.
The contents of the file should probably have a single line like:
bresnan.net esmtp:[69.145.248.18]
Save the file and restart sendmail (or rebuild your sendmail.cf if it must be done manually).
That is quite a long story. A few bullet points (Assuming that mail() returns true and there are no errors in the error log) :
For german speakers, I have written a quite exhaustive "what to do" on this issue some time ago. See here.