I have a script to send a customer an email. We have just noticed that the emails are only being sent to email addresses that end normally like : #gmail.com, #yahoo.com, #Hotmail.com, etc. Whenever we encounter a custom email address like **#platinumpets.com or *#landsberg.com the email address will not ever be received. I can confirm that the server is sending out the email, the user is just never receiving it. We have checked all spam folders and done various Google searches but I have not found any issues this similar to ours. Any ideas? Here is the code :
<?PHP
$subject = "Alert";
$mailheader.= "From: " . "Smartphone Pet Tag Team <support#smartphonepettag.com>\n";
$mailheader.= "X-Sender: " . "support#smartphonepettag.com\n";
$mailheader.= "Return-Path: " . "support#smartphonepettag.com\n";
$mailheader .= "Bcc: support#smartphonepettag.com";
$body .= "Dear " . $ownername . ", \n\n";
$body .= "" . $petname . "'s Smartphone Pet Tag has just been scanned.\n\n";
$body .= "Click here to Login :\n";
$body .= "http://www.smartphonepettag.com\n";
$body .= "********************\n\n";
// $body .= "Scan detected at " . $
//$body .= "Your pets id tag was scanned at the following date and time: " . $datetime; . ", \n";
// $body .= "To stop receive automated alerts click here: \n";
// $body .= 'http://www.smartphonepettag.com/id/alert.php';
// $body .= "and provide your username and password to remove these alerts.
$body .= "Regards,";
$body .= " \n\n";
$body .= "Smartphone Pet Tag Team";
$body .= " \n\n";
$body .= "Keeping Pets Safe and Found";
mail($email_to, $subject, $body, $mailheader ) or die ("Mail could not be sent.");
//end email alert
}
//$id=$_GET["id"];;
if (!$id) {
echo 'You have not entered an ID number. Please go back and try again.';
exit;
}
if ($id=="id=app") {
header("Location: http://www.smartphonepettag.com/id/app.php");
exit;
}
header("Location: http://www.smartphonepettag.com/id/profile.php?id=$id");
?>
I'm not sure where you get &email_to from but this doesn't seem to be the problem anyway.
For me it seems that this is not a problem with PHP. PHP built-in mail functions usually don't use whitelists or anything like this and in your code I can't see any problems relating to what you describe.
But PHP uses the local mailserver installed on your server system. So maybe it's something strange configured on your mail server? You may try sending mails directly via SMTP to find out if the will be sent successful. Depending on your mailserver you may also check the "outbox" (if you not already did).
Otherwise it is definitely a problem with the receiver. PHP generated eMails often look like spam for spam filters. If your are sure that the mail is sent but the problem is not related to the spam filter you don't really have a chance to do anything. You can't change the behaviour of foreign mail servers in this case.
But for me it seems very likely that it's a spam-problem.
Related
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 4 years ago.
So I have a normal but long HTML form on this page
The PHP mail script for the form is:-
$to = "something#gmail.com";
$from = $_POST['contact_email'];
$subject = "Application form submission";
$message = "<h2>Tell us what you need?</h2>";
$message .= "Loan Amount Required ?";
$message .= "<br>";
$message .= $_POST['tell_loan_amount'];
$message .= "<br>";
$message .= "<br>";
$message .= "What For?";
$message .= "<br>";
$message .= $_POST['tell_what_for'];
/* and so on */
$headers = "From: $from" . "\r\n" ;
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset: utf8\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
if( mail($to,$subject,$message,$headers)) {
echo "<h1>Thank you for the Application</h1>";
echo "<p>We will now review the application. This process normally takes 2-3 Business Hours. If we need to discuss any aspect of the application we will contact you. If you have any questions at all please do not hesitate to contact us on <strong>1300 815 462</strong></p>";
}
else {
echo "failed";
}
Now the problem is that mail only gets sent sometimes. I have had several clients contact and said that they successfully reached the thank you page and received the success message but we never received the mail. And yes, not in Spam either.
Is it happening because it is set to gmail?
Or is it happening because of incorrect encoding? (Our clients are filling form in English.)
Or do I need to use mb_send_mail() instead of mail() and remove the encoding code altogether?
use this command on you server it will output what happen to your sent mail :
tail -f /var/log/maillog
sometimes the provider block port 25
I am using PHPMailer to send automated e-mails from my website and while testing, I noticed that when I sent mail from website by Gmail, then e-mails sent by php mailer are generating the following warning on the recipients end:
This message may not have been sent by: example#gmail.com Learn more Report phishing.
But when I use other emails (like yahoo, outlook), then I got no emails in my $contact_email. Please help me to solve this problem.
PHP Mailer code:
<?php
global $_REQUEST;
$response = array('error'=>'');
$user_name = substr($_REQUEST['user_name'], 0, 20);
$user_email = substr($_REQUEST['user_email'], 0, 40);
$user_msg = $_REQUEST['user_msg'];
$contact_email = 'contact.arefin#gmail.com';
if (trim($contact_email)!='') {
$subj = 'Message from Official Website';
$msg = "Name: $user_name
E-mail: $user_email
Message: $user_msg";
$head = "Content-Type: text/plain; charset=\"utf-8\"\n"
. "X-Mailer: PHP/" . phpversion() . "\n"
. "Reply-To: $user_email\n"
. "To: $contact_email\n"
. "From: $user_email\n";
if (!#mail($contact_email, $subj, $msg, $head)) {
$response['error'] = 'Error send message!';
}
} else
$response['error'] = 'Error send message!';
echo json_encode($response);
die();
?>
When you send bulk emails and especially when you mock the sender address, you need to use best practices that may reduce how many servers block you as spammer.
Three things which I think you should do are:
1) Use appropriate mail headers
Add the following to your code - a notice that this is a bulk sender, and the OPT-OUT email address:
.= "X-mailer: YOUR_SITE_DOMAIN Server" . "\r\n"; // this will identify the real sender
.= "Precedence: bulk" . "\r\n"; // this will say it is bulk sender
.= "List-Unsubscribe:info#YOUR_SITE_DOMAIN\r\n"; // this will reveal the OPT-OUT address
Read more about it here
2) Make sure your server domain has a reverse DNS record. This will tell the recipient's server that your domain is REALLY hosted on your server.
3) Publish SPF record with your domain. You can read more about it here, and google it for other big handlers (like Yahoo).
In addition to those, make sure you are adding a footer with a "one click" OPT-OUT removal option and explanation note that this message is sent on behalf, and who is the original sender.
Cheers
You can either set up google apps for your site and get a Username#yourwebsite.com gmail account (more info: http://www.google.com/enterprise/apps/business/), or You will need to set up an e-mail address on your current server that is Username#yourwebsite.com and use that as the $mail->from address.
Your E-Mail recipients are receiving the message because you are telling google to send an e-mail from your server, and then you are telling them that the mail is coming from gmail, which it isn't, it's coming from your personal server. Since the from address and your server address don't match, they flag it as spam. This is googles way of preventing spam, to them it would be the same if you put $mail->from(YOURMOM#LOL.com). The e-mail would still send, but your domain name does not match the # address.
Try this code , In your code i found some mistake which i have solved here.
global $_REQUEST;
$response = array('error'=>'');
$user_name = substr($_REQUEST['user_name'], 0, 20);
$user_email = substr($_REQUEST['user_email'], 0, 40);
$user_msg = $_REQUEST['user_msg'];
$contact_email = 'contact.arefin#gmail.com';
if (trim($contact_email)!='') {
$subj = 'Message from Official Website';
$msg = "Name: $user_name
E-mail: $user_email
Message: $user_msg";
$head = "Content-Type: text/plain; charset=\"utf-8\"\n"
. "X-Mailer: PHP/" . phpversion() . "\n"
. "Reply-To: $user_email\n"
. "To: $contact_email\n"
. "From: $user_email\n";
if (!#mail($contact_email, $subj, $msg, $head)) {
$response['error'] = 'Error send message!';
}else{
$response['error'] = 'success!';
}
} else {
$response['error'] = 'Error send message!';
}
echo json_encode($response); die();
This is my code . When i send an email from an id to its same id then email goes to junk . Unable to identify that what is the problem in this code . For example i send an email like this
From = abc#yahoo.com
To = abc#yahoo.com
Then it goes directly to junk .
<?php
$name=$_POST['fName'];
$yemail = $_POST['yEmail'];
$femail=$_POST['fEmail'];
$message=$_POST['message'];
$from=$yemail;
$to=$femail;
$subject="Invitation for you";
$mailBody ="<table width='628' border='0'>
<tr><td align='left' valign='middle'><p><br><br>Hello,<br><br>This email is a notification to let you know that your friend has invited you to <br>visit this link <a href=www.heed-association.org>Heed Association.</a><br><br> Your friend is using this to help people living in Pakistan by donating some money.<br><br>So your can also contribute in the areas of Health, Education, Environment and Sustainable Development<br> in the earthquake affected areas of Kashmir to improve living conditions and alleviate community distress<br><br><hr><br><br><strong>Regards<br><br>Heed Association</p></td></tr></table>";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: <'.$yemail.'>' . "\r\n";
if (mail($to, $subject, $mailBody, $headers)) {
echo "<script language='javascript'>
window.location = 'index.php';
</script>";
} else {
echo "<script language='javascript'>
window.location = 'tell_a_form.php';
</script>";
}
?>
I would say check your spam filters. As silly as it sounds, add the email to the safe senders list. There doesn't appear to be anything really funky going on in your code.
It's probably an oversensitive spam filter. A lot of programs can detect if the email wasn't actually sent from the email address listed in the "from" column. Usually the way to circumvent this is to have the email come from "no-reply#yourdomain.com".
I've researched this intensely. Here, at Stack Overflow, I've figured out that one needs to use an -f parameter with the php mail() function, if one wants undeliverable mail to bounce back. Following is my script (as it stands now):
//Send Confirmation email. Following are the variables for the email
// mail function best practices: http://collaborate.extension.org/wiki/Best_Practices_Using_the_PHP_mail_Function
$sendto = $email; // this is the email address collected from the foreach routine.
$e_subject = stripslashes($subject); // Subject
//$message = "<html>" . stripslashes($body) . "</html>";
$message = "
<html>
<body>
<p>Hello " . stripslashes($fName) . ":</p>
<div>" . stripslashes($body) . "</div>
</body>
</html>
";
// Always set content-type when sending HTML email
$header = "MIME-Version: 1.0" . "\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";;
// extract user domain so you can set up X-Mailer
$u_domain=substr(strrchr($user_email, '#'), 1);
$dom_array = explode(".",$u_domain);
$user_domain = $dom_array[0];
$header .= "X-Mailer: ". $user_domain ."\r\n";
$header .= "X-Sender-IP: {$_SERVER['REMOTE_ADDR']}\r\n";
$header .= "X-Originating-IP: [".getenv("REMOTE_ADDR")."]\r\n";
$header .= "From: " . $user_email . "\r\n";
$header .= "Sender: ". $user_email . "\r\n";
// The "envelope sender" is the address listed in the "Return-Path:" header - and controls where the email is sent to in the event that a recipient address bounces. http://collaborate.extension.org/wiki/Best_Practices_Using_the_PHP_mail_Function
$header .= "Return-Path:" . $user_email . "\r\n";
$header .= "Reply-To:" . $user_email . "\r\n";
$bounceTo = "-f". $user_email;
// Collect variables from above and insert into the mail() function.
mail($sendto, $e_subject, $message, $header,$bounceTo);
You'll notice a lot of commenting - I'm just trying to figure this out. My mail() sends wonderfully. The mail is coming into my inbox with formatting as it should be. But... the $bounceTo variable ("-f" . $user_email) is not working. I've intentionally mailed to 3 known inactive addresses, and I'm not getting any bounce backs.
All the header settings in the above code are in place because I've learned that these may affect bounce backs. I'm totally willing to get rid of un-necessary headers and add what is necessary. But... at this point the script seems to be a mess -which is not producing bounce backs.
Any suggestions are welcome.
Thanks Much:
Pavilion
Have you looked at the comment posted at http://www.php.net/manual/en/function.mail.php#107321. That might lead you in the right direction.
This thread explaining bounced mail in php might be of benefit to you. I personally have never had to use the -f parameter to handle bounced emails.
Overriding the bounce address with -f is not allowed on all servers, especially if you are on a shared hosting server this is often not possible. In this case, it's often better not to use the very limited mail() function but use a smtp library like phpmailer or swiftmailer instead.
Btw: you don't have to send mails to an inactive address to check your bounce address. Send them to an active account, in the message source look for the "Return-Path" header, this is the bounce address.
This question already has answers here:
php mail function not getting the emails
(6 answers)
Closed 8 years ago.
I have a mail function
$to = "fahad#somewhere.com";
$subject = "Voucher Number: ".$voucher;
$message = '<html><body>';
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr style='background: #eee;'><td><strong>Voucher#:</strong> </td><td>" . strip_tags($voucher) . "</td></tr>";
$message .= "<tr><td><strong>Name:</strong> </td><td>" . strip_tags($name) . "</td></tr>";
$message .= "<tr><td><strong>Phone Number:</strong> </td><td>" . strip_tags($product) . "</td></tr>";
$message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($email) . "</td></tr>";
//set content-type
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
// More headers
$headers .= 'From: <livingdeal#overstock-king.com>' . "\r\n";
$headers .= 'cc:'. $email . "\r\n";
mail($to,$subject,$message,$headers);
For some reason I'm not getting any mail sent at all. The service is hosted so i'm not running it from localhost, and even when I write
if (mail(....))
{ echo "success";
}
else { echo "failed"; }
I always get success, so my suspicion is that it is a problem on the server end. If php mail goes from port 25 is there any way to change the port to a different one in the script? or would it be in php.ini.
Also, would I be able to use a different server (that has a different domain) to send the mail without redirecting the use to that other webpage? I guess in other words can I connect to an smtp server through a php script before sending the mail?
Mail() doesn't send mail, it submits it to the server's mail daemon for sending. If it returns true, that merely means that it was successfully submitted to the queue.
You need to look at the logs of your mail daemon to determine if the messages are in the queue, if they were actually sent, and if not, what error messages were logged when the message failed to send.
BTW, the machine is running a mail daemon, right?
Check with your host, many shared hosting companies are disabling the mail() function to reduce spamming.
you need to be using smtp instead.
apps like wordpress have a simple plugin to handle this change.