I am using the following PHP CODE to send BULK MAIL .But Mails seems to Land in SPAM.I am using "phpmailer" class to send the mail.
require 'mailer/class.phpmailer.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->Username = "info#gmail.com";
$mail->Password = "Bexwa44Puciz"; // GMAIL password
$mail->AddReplyTo('info#gmail.com', 'Info');
$Appname = 'info.com';
$_subject="Newsletter From: ".$Appname;
$ema=",";
$to_bcc=explode(",",$ema);
$mail->AddCustomHeader($headers);
foreach($to_bcc as $tb){
$mail->AddBCC($tb, $dname);
}
$_body ="News content";//$hid;
$mail->FromName = "info.com";
$mail->From="inf#gmail.com";
$mail->Subject = $_subject;
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML($_body);
if($mail->Send()){
echo "Done";
}else {
echo "Failed";
}
I experienced same. My website sends requests for data confirmation to users a few times each day while I do my daily data maintenance. I sent a test message to my Gmail address and found that if you read your mail through Gmail webmail interface it will sometimes tell you Why the message was spammed. Very useful. It gave the reason "A lot of messages from hp19.hostpapa.com were spam". I am on a budget shared server and I assume a hundred other spammers have bought accounts on the same machine as mine and are using it for evil. My site is non-profit so buying a dedicated box to avoid spam is not an option. So...
My solution was to change my CMS to not use PHP mail() at all. Now my CMS simply displays the message and a mailto: link with Subject parameter set. Now my process is to hit CTRL+C, Click the link, CTRL+V, and hit send. Messages are sent from my computer's IP Address (not on any blacklist) using my mail client, Thunderbird.
This takes me just a couple of seconds longer than it did when my CMS used PHP mail() to send the message for me. However I have found I am receiving a lot more replies so I am happy that the vast majority of messages are not getting spam-binned.
I appreciate this manual solution is not appropriate for automated bulk messaging but for small non-profit sites on shared server who trigger each message with a click, I thought it was worth sharing.
There are a number of reasons you could be going into someones spam box. Your email server could be blacklisted due to either you, or another user on your server. You can check it at http://mxtoolbox.com/blacklists.aspx
Also check your SPF records in your DNS
Related
I am working on Laravel and I am trying to send an email with PHPMailer and my mail server is Zoho.
Here is my Code:
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'smtp.zoho.com';
$mail->SMTPAuth = true;
$mail->Username = 'ServerUserName';
$mail->Password = 'ServerUserPassword';
$mail->SMTPSecure = 'TLS';
$mail->Port = 587;
$mail->setFrom('itsupport#foo.net', 'Foo');
$mail->addAddress($email);
$mail->addReplyTo('noreply#foo.com', 'No-reply');
$mail->isHTML(true);
$mail->Subject = "Testing - " . $subject;
$mail->Body = $body;
if(!empty($attachment)) {
$mail->AddAttachment($attachment['abs_path'], $attachment['name']);
}
$mail->SMTPDebug = 2;
$mail->Debugoutput = function($str, $level) {echo "debug level $level; message: $str"; echo "<br>";};
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
echo "Error"."<br>"."================================="."<br>"."<br>";
dd($mail);
} else {
$error = 'Message sent!'.$mail->ErrorInfo;
echo "Success"."<br>"."================================="."<br>"."<br>";
dd($mail);
}
My Scenarios
1) When I am sending an email with my Valid and Real email it gives me
success status and in my mail server its shows me in Sent tab.
2) But when I am sending an email with Valid but Fake email it gives me also Success status and when I check my mail server It gives
me this mail.
3) And in both scenarios in my debugging code it gives me always this return:
What I want
I want when a mail server return undelivered or failed mail it should return me an error code e.g. (550, 552, 553 etc) + Error Message. I search a lot but not find anything.
Is there any possibility that server return me the error code also.
Note: I tried my phpmailer code in try catch. But when I use fake email it dos not goes to catch.
You're misunderstanding the structure of email. Email uses an asynchronous store-and-forward approach, which means that can be sent successfully, but fail later, before it reaches its destination. This is completely unlike HTTP which gives immediate responses.
You are submitting the message successfully to Zoho's mail server, but then that server is failing to deliver the message to its intended destination, so it gets sent back as a bounce to the envelope sender address (the address in the SMTP MAIL FROM command, set via the Sender property in PHPMailer).
To handle bounces in your code, you can configure your mail server to pipe the inbound message into a script attached to your bounce address, for example as described in this article.
Unfortunately that's not the end of the story. While you will then have programmatic access to the bounced message, actually figuring out why it bounced and who bounced it is often difficult, if not impossible in some cases. For example, Microsoft Exchange sometimes sends bounces that do not contain any means of identifying the address the original message was sent to! You can address that particular shortcoming by using VERP addressing, where every message has a unique bounce address, which you can do with PHPMailer.
Writing bounce handlers is generally a very unpleasant experience that I recommend avoiding if you can. There is a commercial bounce classification library by BoogieTools that works well, but there is still a large element of guesswork and heuristics involved.
everybody,
I am working on Email system to send emails via SMTP protocol with PHP,
everything goes fine and now I can send messages without a problem, I have tow problems Actually and I hope I will find a solution,
1 - I send email to users using a phpmailer library, but I can not control and get the result of sending email because I send about 10 emails at one SMTP connection.
this is my send code
$mail = new PHPMailer;
$froms=$respu['froms'];
$mail->Timeout = 3600;
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = $respu['server']; // Specify main and backup SMTP servers
$mail->SMTPAuth = $respu['authentication']; // Enable SMTP authentication
$mail->Username = $respu['username']; // SMTP username
$mail->Password = $respu['password']; // SMTP password
$mail->SMTPSecure = $respu['security']; // Enable TLS encryption, `ssl` also accepted
$mail->Port = $respu['port']; // TCP port to connect to
$mail->SetFrom($respu['username'],$froms);
$mail->AddAddress($to);
$mail->Subject = $subject;
$mail->MsgHTML($message);
if(!$mail->Send()) {
//$errors=$mail->getSMTPInstance()->getError();
$date=date('Y-m-d h:i');
echo $msg= "Message Not Sent: to $to " . $mail->ErrorInfo;
$date=date('Y-m-d h:i');
$sql="insert into log (log_text,user_email,log_time,status)values ('$msg','$to','$date',0) ";
$this->query_return($sql);
exit();
} else {$date=date('Y-m-d h:i');
$sql="insert into log (log_text,user_email,log_time,status)values ( 'Message Sent Successfully ','$to','$date',1) ";
$this->query_return($sql);
}
the if(!$mail->Send()) condition return true every time even if the email is wrong . it working like to test if the SMTP connection is done or not, I want to know if the email received by users or not.
my second problem is, I have more than 3000 mail address and I want to send email to them at the same time, what is happening is the procedure take a long time and I have to wait for a long time to finish it, how can I do it faster.
For sending to lists, use the mailing list example provided with PHPMailer as a starting point. Also read the wiki article about sending to lists.
For maximum performance, you want to be submitting to a local or nearby mail server, which then takes responsibility for onward delivery. Some messages may fail to be delivered, in which case you will need to rely on bounce handlers; when a message fails to send, it will be returned to the Return-path address, which you can control by setting the Sender property in PHPMailer (by default it uses your From address). Note that as a sender you should never set a return-path header yourself; that's the receiving server's job.
Be warned though: handling bounces is very unpleasant; because bounce messages are fairly "invisible" in normal use, it means that they are extremely variable in quality. For example, it's possible for bounces from some Microsoft Exchange servers to omit the address that the message bounced for! You can handle that scenario (and many other shortcomings of badly-configured mail servers) by using VERP addressing to help you identify original recipient addresses, or even individual messages. However you deal with this, you need to be on very good speaking terms with your mail server. Using an external service to handle sends like this isn't necessarily any better, since they face exactly the same problems, though at least they may deal with much of the unpleasantness of bounce handling.
FYI I run https://smartmessages.net, an email marketing service; it's built around PHPMailer (which is partly why I'm the maintainer), and we can send at about 300 messages/second (using a very good mail server), so decent throughput is entirely possible with PHPMailer.
I'm trying to use PHPMailer on my website to send mail as part of a contact form. I would like to use contact#example.com instead of standard_email#example.com to send mail, for filtering and security. My mail is handled by GSuite (formerly called Google Apps) and is setup like below:
User - standard_email#example.com
Alias - contact#example.com --> standard_email#example.com
I have sending working perfectly when using standard_email#example.com in the PHPMailer configuration, but when I try to send using the alias it does not work. Is this not possible with GSuite aliases?
Contact Controller
define("SMTP_HOST", "smtp.gmail.com");
define("MAIL_ADDRESS", "alias#example.com");
define("SMTP_USERNAME", "alias#example.com");
...
//Configure SMTP authentication
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = SMTP_HOST;
$mail->SMTPAuth = true;
$mail->Username = SMTP_USERNAME;
$mail->Password = SMTP_PASSWORD;
$mail->SMTPSecure = "tls";
$mail->Port = SMTP_PORT;
//Set email headers
$mail->setFrom(MAIL_ADDRESS, "Contact Us Submission");
$mail->addAddress(MAIL_ADDRESS, "Contact Us Submission");
$mail->addReplyTo($form_email, $form_name);
$mail->isHTML(true);
//Set email content
$mail->Subject = htmlspecialchars($form_subject);
$mail->Body = htmlspecialchars($form_comments);
$mail->AltBody = htmlspecialchars($form_comments);
//Attempt to send the message and display the results to the user
if ($mail->send() == false) {
return new MailResponse(1, "Message could not be sent", $contactSubmission);
} else {
return new MailResponse(0, "Message sent successfully", $contactSubmission);
}
I've also tried using standard_email#example.com as the SMTP_USERNAME and alias#example.com as the MAIL_ADDRESS, but that didn't work either.
Results
There are no reported errors, and the page displays the "success" mail message; however, no mail is actually sent/received when I visit my user. Since GSuite apparently routes all of the alias mail to my standard address, I should be seeing it.
Let me know if I'm missing something, and thanks!
The solution from #Synchro works and for convenience here is a short step by step solution:
On your computer, open Gmail.
In the top right, click Settings Settings and then See all settings.
Click the Accounts and import or Accounts tab.
In the "Send mail as" section, click Add another email address.
Enter your name and the address you want to send from.
Click Next Step and then Send verification.
Click Add Account
Learn more: https://support.google.com/mail/answer/22370?hl=en
Everything should be working now :)
Hi i am currently implementing an email system for a customer in php. I'm having a bit of trouble in figuring out something. Here's a sample code:
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 0; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = "***missing part***";
$mail->Password = "***missing part***";
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
My customer already created a business email account on gmail for this website. My question is should i put this business email and password in these missing parts? Anyone could help me please? Thanks.
whose username and password should i put there?
If you want to use GMail, you need to put in the username and password that belong to the GMail account you want to send the message from.
.... which is why sending E-Mail through GMail is a bit of an imperfect solution IMO - you put your personal Google login data, with which you can access everything you do on Google, into a script on a server. It's not great practice security-wise.
It might be more feasible to create a SMTP account on the client's web site, and use that. That has the additional advantage that you can use a email#clients-domain-name.com sender address.
you must post the username and password so we can help you.. LOL, just kidding. You should put there the username and password of the account that would be sending the email. In this case, probably your webpage's gmail account.
Often web hosts don't use authentication for their web servers to send email using their smtp servers, i would suggest contacting the people who host the website and ask them about using their smtp servers.
Using gmail (if you can from a script) might end up with the rather annoying reply thing that you get from gmail where the reply address is a gmail account.
e.g. from mrKoz#gmail.com on behalf of mr#koz.com which doesn't look awesome :)
I am using PHPMailer to send a confirmation email for newly registered users in my social network. But I found out most of them have ended up in user's spam list. (Hotmail and Yahoo). How to avoid this?
This is my script
$mail=new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = mSMTPAuth();
$mail->SMTPSecure = mSMTPSecure();
$mail->Host = mHost();
$mail->Port = mPort();
$mail->Username = mUsername();
$mail->Password = mPassword();
$mail->From = mFrom();
$mail->FromName = "SiteName";
$mail->Subject = "SiteName New Account Activation";
$mail->IsHTML(true);
$mail->WordWrap = 50;
$mail->Body = "<h2>Welcome to " .$sitename. " " .$username. "! </h2><br><br>";
$mail->Body .= "Please click on the link below to verify your email address:<br><br>";
$mail->Body .= "<a href='".$base. "verify.php?a=" .$gen_key."'>".$base. "verify.php?a=" .$gen_key."</a>";
$mail->Body .= "<br><br>Regards<br>";
$mail->AltBody = "Welcome to " .$sitename. " " .$username. "!\n\nTo verify your email address, please click on the link below:\n\n".$base. "verify.php?a=" .$gen_key;
$mail->AddAddress($email);
$mail->Send();
$mail->ClearAddresses();
To maximize the odds of your email arriving, there are three things you need to check:
Make sure the computer sending the email has a Reverse PTR record
Configure DomainKeys Identified Mail (DKIM) in your DNS and code
Set up a SenderID record in your DNS
details at:
http://www.codinghorror.com/blog/2010/04/so-youd-like-to-send-some-email-through-code.html
There's not much you can do about it. Most of those mail providers have lists of common IP addresses, hostnames, and other data that often get flagged as spam and if your emails match the criteria they automatically get filtered. All you can really do is tell your visitors to add your email address to their allow list before registering so the email will go through to their inbox.
Honestly, don't worry about it. If they see your emails are regularly being marked as 'not spam' then they'll eventually add an exception for it. Just tell users to check their spam folder if they don't see the email like every other site does. Usually if they mark it as 'not spam' in that folder it will automatically add an exception for that address so any other emails you send them will end up in their inbox.
Do you have a reverse DNS entry for the server sending the confirmation e-mails?
If not, this might be a rDNS issue. Some sites are much more likely to mark a message as SPAM if the IP and name of the sending host don't match according to rDNS.
Otherwise, you might try sending confirmation e-mails to your own accounts on major e-mail sites like yahoo, hotmail and g-mail and then tweaking the wording until it gets past the spam filters.
Hm, there is SOMETHING you can do:
* Scrap the HTML. This looks like spam, especially with low text
* Write some more text, please.
Short HTML mails may rise up quite on the spam list.
I discovered that any variation of the word "confirm" in the title ends up in my spam bucket. I found other words that also do this: "purchase", "hurry", "order", "bargain", and "imminent".
This may not be true in all emails, but it happens in mine. It may be because those words appear in most of the emails I mark as span. It also may be that a local sysop made a filter and distributed it to all of us.
You can try using sendGrid apis which will helps, they charge but I think it is worthy. They support most popular languages : Nodejs, PHP, Java, ....