PHP mail is not sending, but result is true - php

i use phpmailer for sending emails. in one script, the code works fine, in other exaple, result is true, but no mail is delivered. error log is empty, what would you recommend to check?
thanks
include_once '/var/www/xxxxxx.cz/web/php/phpmailer.php';
$to = 'dubcznic#gmail.com';
$to_name = '';
$from = 'robot#xxxxxx.cz';
$from_name = 'Robot';
$mail = new phpmailer();
$mail->CharSet = 'UTF-8';
$mail->From = $from;
$mail->FromName = $from_name;
$mail->AddAddress($to, $to_name); // Add a recipient
$mail->AddCC('nabytek-safr#xxxx.cz');
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->IsHTML(true); // Set email format to HTML
$mail->Subject = 'Import Robot Autronic';
$mail->Body = 'xxx';
$mail->AltBody = str_replace("<br />", "\n", 'xxx');
if (!$mail->Send())
{
echo 'Mail Error: ' . $mail->ErrorInfo;
exit;
}
else
{
echo 'OK';
}
die();

Check what text you are sending. It could be that your results are being filtered out and put in a Spam folder. Sometimes a mail with 'test' in the title could be sent right to Spam.

It is impossible to verify that an email was delivered with PHP.
Check your mail server log (usually /var/log/mail) to see if the email was sent.
Send a BCC to an email address that you know has no spam filters.

You can validate real emails with Telnet and MX records. See this answers
https://stackoverflow.com/a/17332773/468891

First, check your spam, if you haven't already.
Second, change your SMTP settings to that of gmails, put your gmail log in and password and try.
If a mail fails to deliver you'll get an delivery- failure notification with possible causes of failure, which helps a lot. A delivery failure can also happen when no error is displayed in PHP.
This always helps me.

Related

phpmailer not sending email to gmail,yahoo,hotmail or these are blocking email sent by phpmailer

i am using PHPmailer to send emails
here is code that i have used:
$mail = new PHPMailer();
$subject = "test";
$to = "test_patel#yahoo.com"
$mail->SetFrom("PDSociety#aol.com","Punjab Dental Society");
$mail->AddReplyTo("PDSociety#aol.com", "Punjab Dental Society");
$mail->Subject = $subject;
$mail->MsgHTML($str);
$mail->AddAddress($to, "Punjab Dental Society");
if(!$mail->Send())
{
$err = "Mailer Error: " . $mail->ErrorInfo;
//echo $err;
} else {
$msg = "Message sent!";
}
// Clear all addresses and attachments for next loop
$mail->ClearAddresses();
if i change email address from yahoo to gmail or hotmail, still email are not sent.
i checked by echoing error, but no errors.
can anyone explain what is the issue ?
After trying various ways, i found following code working with almost all email providers
$to['email'] = "recipients email address";
$to['name'] = "name";
$subject = "email subject";
$str = "<p>Hello, World</p>";
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = 'Specify main and backup server here';
$mail->Port = 465;
$mail->Username = 'xyz#domainname.com';
$mail->Password = 'email account password';
$mail->SMTPSecure = 'ssl';
$mail->From = 'From Email Address';
$mail->FromName = "Any Name";
$mail->AddReplyTo('xyz#domainname.com', 'any name');
$mail->AddAddress($to['email'],$to['name']);
$mail->Priority = 1;
$mail->AddCustomHeader("X-MSMail-Priority: High");
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body = $str;
if(!$mail->Send()) {
$err = 'Message could not be sent.';
$err .= 'Mailer Error: ' . $mail->ErrorInfo;
}
$mail->ClearAddresses();
variable values needs to be changed accordingly.
Hope these helps people having issues with PHPmailer
PHPMailer is only involved in submitting the message to your own mail server, and you're not having any problem there. After that, your mail server takes on the responsibility of sending it on, so you will find the answer in your mail server's logs.
There is no simple way to ensure messages end up in the inbox and not spam - if there was, spammers would be using it and filtering would be useless. Make sure your DNS resolves backwards and forwards, that you have valid SPF records, that you sign your messages with DKIM (especially important for Yahoo) and most importantly, that you don't send messages that your recipients think are spam.
Try this :
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SMTP
try {
$mail->AddAddress($to['email'],$to['name']);
$mail->FromName = '';
$mail->Subject = $subject;
$mail->MsgHTML($message);
$send = true;
return $mail->Send();
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
$e->getMessage(); //Boring error messages from anything else!
}
It will help you if any exception error.
Have you looked on the post here: Using PHPMailer Results in many blocked emails? The asker solved the issue by changing the email subject:
Well I solved the issue; the code above was not the problem and works
great.
In my subject, I used a phrase regarding "verify your account
information" and that got it blocked on a few ISP's.
So the lesson is, your subject matters. I was looking at my php code
and my body content before I realized this.
The content of the email and its subject can make ISPs ban it. You could try taking the content of one of your received emails from your inbox and see if that goes through.

PHPMailer best solution for looping through emails

I am trying to build a recall system in which users are sent reminder emails based on specified criteria. At the moment I would probably be sending 10-15 reminders at a time each week but it's possible that this may escalate to hundreds each week in the future. I've decided to use PHPMailer class to handle mail sending but I am very new to PHPMailer and so i'm not sure if the solution I have come up with will give the best performance or if my code can be improved. Also I am storing the date the email has been sent once it has been sent successfully.
This is what I have come up with:
<?php
//I have left out the database connection details for obvious reasons
require 'PHPMailer-master/PHPMailerAutoload.php';
$result = mysql_query("SELECT * FROM patients_test WHERE recall <> 0 AND DATE_ADD(`last_seen`, INTERVAL recall DAY) < DATE_ADD(NOW(), INTERVAL 21 DAY)");
while($row = mysql_fetch_array($result))
{
//Create new mail object
$mail = new PHPMailer;
///Mail settings
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'host.co.uk'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'myusername'; // SMTP username
$mail->Password = 'mypassword'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = 'myusername';
$mail->FromName = 'Mailer';
$mail->addReplyTo('replytoadd', 'Information');
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Reminder email';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
//Recipient info
$ref = $row['identifier'];
$first_name = $row['first_name'];
$surname = $row['surname'];
$email = $row['email'];
$mail->addAddress($email, $first_name." ".$surname); // Add a recipient
if(!$mail->send())
{
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
else
{
echo 'Reminder sent to '.$first_name.' '.$surname.' successfully<br/>';
mysql_query("UPDATE patients_test SET last_reminder= CURDATE() WHERE identifier='$ref'");//Update database to show that email has been sent
$mail->clearAllRecipients();
}
}
?>
Also the reason why I chose not to use PHPs default mail() function is because I am worried that my emails will be blocked as spam and I read somewhere that using something like PHPMailer can reduce the chances of this happening. Does anyone have any advice on this issue?
Thanks in advance
Rich
Fill the mail's headers can reduce this issue. The mail server have some rules which define if the mail is a spam or not. Moreover, sending mails through a loop may cause a blocking depending on how it is configured.

i am submitting my form with php but it is going to spam

**> the mail posted with the below given is going to spam. I am not using
captcha in the form as i don want to. So can anybody help me to the
mail in Inbox**
<?php
if(isset($_POST['submit']))
{
$name = $_POST['Name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$date = $_POST['checkinDate'];
$package = $_POST['package'];
$person = $_POST['adults'];
$kids = $_POST['kids'];
$ip=$_SERVER['REMOTE_ADDR']; //trace the ip address of the user submited
$subject ="Query From :Kerala-Honeymoon-Packages - Promotion\n"; //subject of the email
$to="paul#roverholidays.com";
$cc="online#roverholidays.com";
$ccc="deepti#roverholidays.com";
$from=$_POST['email'];
$adc="Name :$name\n";
$adc.="Email :$email\n";
$adc.="Phone :$phone\n";
$adc.="Date of Travel :$date\n";
$adc.="Package :$package\n";
$adc.="Adults :$person\n";
$adc.="Kids :$kids\n";
$message ="$name copy of the query you submited in Kerala-Honeymoon-Packages";//message header to user submited
$headers="From: <".$from. ">" ;
mail($cc,$subject,$adc,$headers);
mail($ccc,$subject,$adc,$headers);
mail($email,$message,$adc);
header("Location: thanks.htm");
}
else
{
return false;
}
?>
coding-wise I don't think there is anything you can do because it is the email server that classifies your email as a spam not the way you coded your script. All you can do is to control it from the receiver email setting i.e you setup your gmail filters to detect that email based on keyword like "Kerala-Honeymoon-Packages" and move it out of spam.
I don't know for sure what the email servers algorithms are for marking email as spam. However, I think sending email from different domain rather than your domain name is likely to be detected as phishing email. what I mean is when someone put his/her yahoo email in the form and click on send, your server will send the email to emails addresses in the script but it will send it as if it came from yahoo, which will be suspicious for the receiver email server as it knows that it did not come from yahoo.
Many email services block mail sent directly from random servers because they have little to no reputation as a legitimate source of non-spam emails. Instead of using the straight php mail() function, try using a SMTP service like Mandrill or Gmail's SMTP service. Both are free.
Here is the configuration page for Mandrill:
http://help.mandrill.com/entries/23737696-How-do-I-send-with-PHPMailer-
<?php
require 'class.phpmailer.php';
$mail = new PHPMailer;
$mail->IsSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.mandrillapp.com'; // Specify main and backup server
$mail->Port = 587; // Set the SMTP port
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'MANDRILL_USERNAME'; // SMTP username
$mail->Password = 'MANDRILL_APIKEY'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = 'from#example.com';
$mail->FromName = 'Your From name';
$mail->AddAddress('josh#example.net', 'Josh Adams'); // Add a recipient
$mail->AddAddress('ellen#example.com'); // Name is optional
$mail->IsHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <strong>in bold!</strong>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->Send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';

PHPMailer With Attachment Never Received

I am tying to send an email with an attachment using phpmailer.
include_once('/home/site/PHPMailer/class.phpmailer.php');
$mail = new PHPMailer();
$body = $mail->getFile('contents.html');
$body = eregi_replace("[\]",'',$body);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.free.fr"; // SMTP server
$mail->IsSendmail(); // telling the class to use SendMail transport
$mail->From = "name#sub.fr";
$mail->FromName = "name";
$mail->Subject = "subject";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAddress("sub#sub.net", "name");
$mail->AddAttachment("mylist.csv"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
I receive a "Message sent !" on execution, but no email is ever received.
It is very possible the user you sent the email to did not recieve it due to the fact a lot of mail providers such as AOL and Yahoo block massive amounts of Ip addresses related to email spam. So if the server you are running this php script from is on their blacklist the user will not even receive it to the spam folder.
Check your php email logs.
http://help.yahoo.com/l/us/yahoo/smallbusiness/webhosting/php/php-03.html
Also, if this is not the case, try making sure the file your trying to include exists, and you are passing the correct path to the file. Like #Waygood said, try seeing if it sends without the attachment.

Sending an email via php mailer I get "myemail via host.blabla" in sender, how to remove that?

I have this phpmailer which is blasting emails and when recieving the email the sender is : myemail#myemail.com via web258.opentransfer.com (my host)
thats my code:
// Real Email Blast:
$mail = new PHPMailer();
$mail->From = "myemail#email.com";
$mail->FromName = "myname";
$mail->AddAddress($email, $name);
$mail->Subject = $htmlTitle = stripslashes($reSubject);
$mail->Body = $htmlBody = "
<div style='direction: rtl; text-align: right;'>
".stripslashes($reEmailContents)."
</div>";
// Setting plain text:
$text_body = $htmlTitle."
".strip_tags($htmlBody);
$mail->AltBody = $text_body;
if (!$mail->Send()) {
// Email failed error, resending user to landing page:
$error .= "<span style='color: #D20005;'>- Failed sending email to: ".$email." (".$name.")</span><br>";
}
that's especially visible on outlook and on gmail when you access the email itself you can see it on the sender box - how can I remove this and send without the host?
That's the intention of the "via yourdomainhere.com"
I don't believe you can change it, unless you run a custom mail server on your site (which may not be possible on a shared host)
Irregardless, your question would probably be better suited for ServerFault since PHPMailer isn't the issue.

Categories