some1
some1

Reputation: 1737

How can I test why sendmail / php isn't working?

I have the php.ini configured correctly, I think...

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = /usr/sbin/sendmail -t -i 

php is working fine in general. phpinfo() looks fine.

I have a script I'm using to send a test message, and it claims to work..

<?php
ini_set( 'display_errors', 1 );
error_reporting( E_ALL );
$from = "[email protected]";
$to = "[email protected]";
$subject = "PHP Mail Test script";
$message = "This is a test to check the PHP Mail functionality";
$headers = "From:" . $from;
mail($to,$subject,$message, $headers);
echo "Test email sent";
?>

I always get a message that says: "Test email sent"

But nothing ever shows up in gmail?? What gives, how should I troubleshoot?

Upvotes: 0

Views: 457

Answers (4)

skycrew
skycrew

Reputation: 918

mail() is boolean function.

$check = mail($to,$subject,$message, $headers);
var_dump($check);

var_dump will return either true or false.

if false, there are something wrong with the configurations or codes.

however, to briefly debug your mail() function, I need to know, what is your OS? what type of web server u use?

Upvotes: 0

Dorvalla
Dorvalla

Reputation: 5240

If you work with a contact form, double check your variables. In your case they are hard coded, but it is always good to perform a check. This is a simplified checker. (I edited out my checks for variables that are supposed to be send with the message)

    if (mail ($to, $subject, $body, $headers)) {
         echo '<p>Message Send.</p>';
    } else {
         echo '<p>Something went wrong, not delivered.</p>';
    }

Upvotes: 1

Nils
Nils

Reputation: 779

First and quickest: check your spam folder. Gmail has a tendency to filter out messages not coming from a well-established mail server.

Second, check the sendmail logs on the server sending the e-mails. The logs should tell you whether the receiving SMTP server has accepted the message.

That the mail function returns success only means that the local sendmail script accepted the e-mail, not necessarily that the e-mail was sent.

Upvotes: 1

Ari&#235;n van Helden
Ari&#235;n van Helden

Reputation: 96

Try this:

if(mail($to,$subject,$message, $headers))
{
echo "Test email sent";
}

This will check if the mail is sent and if it is, it will echo "Test email sent".

Upvotes: 1

Related Questions