0

I am using the php mail() function to send mails from my server. It was working fine before but now I am not getting the simple mail. Mail status is TRUE but emails are not being received. I tested it on the other server its working fine there.

Here is my code:

$to = 'myemail@gmail.com';
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$phone_number = trim($_POST['phone']);
$message = trim($_POST['message']);
$subject = 'Contact Message from  - ' . strip_tags($name);
$headers = "From: " . $name . " <" . $email . "> \r\n";
$headers .= "Reply-To: " . strip_tags($email) . "\r\n";
$headers .= "Content-type: text/html \r\n";
$message = '<html><body>';
$message .= '<h1>Hello, </h1>';
$message .= '</body></html>';
$message .= '<html><body>';
$message .= '<table rules="all" style="border-color: #666; border:1px solid;" cellpadding="10">';
$message .= "<tr><td><strong>Name:</strong> </td><td>" . $name . "</td></tr>";
$message .= "<tr><td><strong>Email:</strong> </td><td>" . $email . "</td></tr>";
$message .= "<tr><td><strong>Phone Number:</strong> </td><td>" . $phone_number . "</td></tr>";
$message .= "<tr><td><strong>Message:</strong> </td><td>" . $message . "</td></tr>";
$message .= "</table>";
$message .= "</body></html>";
$confirmation = mail($to, $subject, $message, $headers);
if ($confirmation) {
    print "<meta http-equiv=\"refresh\" content=\"0;URL=thanks.php\">";
} else {
    print "<meta http-equiv=\"refresh\" content=\"0;URL=error.php\">";
}
  • show your spam, or it comes from your configuration serveur (if you use smtp serveur or not), you must check with your host server. – MouradK Dec 29 '14 at 10:36
  • Thanks @MouradK but its not even in the spam I contact to the server support they are saying its content error I tried sending simple mail just plain text but that was not working too. – Dimple Thakur Dec 29 '14 at 10:46
  • i m sure that comes from your server configuration if it return "true" , should try to use smtp server (see www.mailjet.com )... – MouradK Dec 29 '14 at 10:49
  • Thanks, You mean there is the server smtp_port issue? – Dimple Thakur Dec 29 '14 at 10:53
  • depend of your host, it perhaps that block email, and perhaps use a default smpt server on their php.ini (or overwrite it). At least , with tool like mailjet it should work (for use it see http://stackoverflow.com/questions/14456673/sending-email-with-php-from-an-smtp-server ) – MouradK Dec 29 '14 at 10:57

2 Answers2

0

At first check a simple mail.

<?php
ini_set('display_errors',1);

$email = '';//<--your mail
if (mail($email, 'test', 'test') {
    echo 'send';
} else {
   echo 'problems';
}

Run it. Check your email, if do not send - see errors on display.

Dima Serg
  • 13
  • 3
0

Check server's SMTP setting may be its incorrect, alternative you can use this simple SMPT send mail script.

Wiram Rathod
  • 1,805
  • 1
  • 19
  • 39