0

I am facing an unexpected issue with a PHP mailfunction. The script sending email to all email address but not to my domain.

Suppose I send email to nitinsoni@gmail.com it was received but when I send email to nitin@mydomain.com it was not received.

I am using GoDaddy web hosting and PHP mail function. SMTP is also not working on GoDaddy server.

PHP code is as follows:

<?php

$to      = 'nitin@mydomain.com';
//$to      = 'nitinsonitest@gmail.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: nitinsonitest@gmail.com' . "\r\n" .
    'Reply-To: nitinsonitest@gmail.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

$r  = mail($to, $subject, $message, $headers);
if($r) {
    echo 'mail sent';
}else {
    echo 'not sent';
}
die;

?>

And SMTP email via PHPMailer is not working as well:

<?php
echo "<pre>";

//die('ada');
require 'PHPMailerAutoload.php'; 

$mail = new PHPMailer();
$mail->Host = "relay-hosting.secureserver.net"; // your SMTP Server
$mail->IsSMTP();
$mail->PORT = 465;
$mail->SMTPDebug=true;
$mail->SMTPAuth = true; // Auth Type
$mail->SMTPSecure = "ssl";
$mail->Username = "user@gmail.com";
$mail->Password = "password";
$mail->Sender = "user@gmail.com";
$mail->From = "user@gmail.com";
$mail->AddReplyTo("user@gmail.com");
$mail->FromName = "user ";
$mail->AddAddress("recepient@gmail.com");
$mail->IsHTML(true);
$mail->Subject = "Test subject";
$mail->Body='Test Subject';
$mail->WordWrap = 50;
if($mail->Send())
{
    echo"<script>alert('The Form has been posted ,Thank you');</script>"; 
}
else
{
    echo 'mail error';
}
Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
Nitin Kumar Soni
  • 198
  • 2
  • 16

1 Answers1

0

Suppose I send email to nitinsoni@gmail.com it was received but when I send email to nitin@mydomain.com it was not received.

I am using GoDaddy web hosting and PHP mail function. SMTP is also not working on GoDaddy server.

I doubt this has anything to do with the coding when using mail or PHPMailer. The thing is just because you send a mail, it doesn’t mean that the receiving end thinks the mail is valid. And chances are the receiving end—even if it is your domain—has decided a random e-mail sent off of a random server is simply SPAM.

I have posted a more detailed answer here, but when it comes to SPAM it basically boils down to this: Do you have an SPF (Sender Policy Framework) record setup for your domain? Do you also have a PTR (reverse DNS) record set for that domain?

If you do not have an SPF or PTR record, the chance of your message simply being flagged as SPAM is quite high.

If you are serious about sending mails off of your server, you need to at least get your SPF record & PTR record set.

Community
  • 1
  • 1
Giacomo1968
  • 25,759
  • 11
  • 71
  • 103