I am hosting my own website instead of using a regular paid webhost and use PHPmailer to send out notices to my users. I want to keep my mail from going to their spam folder. I am using my internet host as my SMTP to send the mail and ZOHOmail to receive the mail.
Here is the code to send the mail:
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp-server.tampabay.rr.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '******#tampabay.rr.com'; // SMTP username
$mail->Password = '******'; // SMTP password
//$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = 'webmaster#picknflgames.com';
$mail->FromName = 'Pick NFL Games';
$mail->addReplyTo('webmaster#picknflgames.com');
//$mail->addReturnPath('webmaster#picknflgames.com');
// $mail->addAddress('webmaster#picknflgames.com'); // Name is optional
// $mail->addCC('$TE');
// $mail->addBCC($value);
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
I read where I could enable SPF, but I am not sure if that can be done with my internet hose email. Maybe I should try using ZOHOmail to send.
Here are the headers from a recent email:
From: Pick NFL Games <webmaster#picknflgames.com>
Subject: Season is fast approaching
Date: August 27, 2015 11:30:35 PM EDT
To: Patrick Lewis <patrick#patricklewis.net>
Reply-To: webmaster#picknflgames.com
Delivered-To: patrick#patricklewis.net
Received-Spf: Pass (zoho.com: domain of webmaster#picknflgames.com designates 173.169.21.54 as permitted sender using best guess ) client-ip: 173.169.21.54
Return-Path: <webmaster#picknflgames.com>
Return-Path: <webmaster#picknflgames.com>
Received: from cdptpa-oedge-vip.email.rr.com (cdptpa-outbound-snat.email.rr.com [107.14.166.226]) by mx.zohomail.com with SMTP id 144073263762811.694320566534088; Thu, 27 Aug 2015 20:30:37 -0700 (PDT)
Received: from [173.169.21.54] ([173.169.21.54:32798] helo=10.0.1.99) by cdptpa-oedge03 (envelope-from <webmaster#picknflgames.com>) (ecelerity 3.5.0.35861 r(Momo-dev:tip)) with ESMTP id E9/20-20019-CD5DFD55; Fri, 28 Aug 2015 03:30:36 +0000
Message-Id: <a0634c40fd39d8be6126636437ceda96#10.0.1.99>
X-Priority: 3
X-Mailer: PHPMailer 5.2.8 (https://github.com/PHPMailer/PHPMailer/)
Mime-Version: 1.0
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-Rr-Connecting-Ip: 107.14.168.142:25
X-Cloudmark-Score: 0
X-Zohomail: ZRCVF-BYFANCY_1 SS_1 SFPD SFPP UW11 SFP_WHTCNT_EXT SGR4_1_11085_176
X-Zohomail-Owner: <a0634c40fd39d8be6126636437ceda96#10.0.1.99>+zmo_1_<webmaster#picknflgames.com>
X-Zohomail-Sender: 173.169.21.54
X-Zoho-Virus-Status: 2
It is always better to use well-known SMTP server to solve such issues. You can use gmail for example (it allows you to send emails via SMTP/SSL), but if you want to send emails from your host you should do the followign things to make sure your host is not treated as spam host:
Make sure your host is not open relay: i.e. anonymous can't conntect to its 25 port and send anything to anyone (there are open relay check engines over the Internet, use them)
Have some meaningful reverse DNS record. Your IP should resolve to something like mx.<YOUR_EMAIL_DOMAIN>, not 44.33.22.191.clients-dsl.my.local.isp.net
Use SPF: you should have v=spf1 YOUR_HOST_IP record for your email domain (YOUR_EMAIL_DOMAIN)
These 3 steps increase your chances to send emails from some_user#YOUR_EMAIL_DOMAIN with out of getting into "spam" folder.
How ever, antispam policy is not always clear, so there is no 100% guarantee
Related
I have a feedback form, this script is filtering and validating data and writing data to the database. At the very bottom, through include, I connected a script with PHPMailer, which sends the text of the feedback form to my mail via gmail smtp.
If I comment out the script connections, then the form is submitted either immediately or after 1 second. With him, he can wait 2-3 seconds.
I submit form data via XMLHttpRequest, remotely. Upon successful submission, the form is reset to zero and the submit button becomes inactive, and via pop-up notifications I display the server's response. So it happened that I managed to press the send button 2-3 times until the script worked and, accordingly, several records were created and several letters were sent to the mail. Is this how it should be or have I configured PHPMailer wrong?
Let me know what data I need to attach. This is my PHPMailer script:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require $_SERVER['DOCUMENT_ROOT'] . '/form/PHPMailer/PHPMailer.php';
require $_SERVER['DOCUMENT_ROOT'] . '/form/PHPMailer/Exception.php';
require $_SERVER['DOCUMENT_ROOT'] . '/form/PHPMailer/SMTP.php';
$mail = new PHPMailer;
$mail->CharSet = 'UTF-8';
$mail->isSMTP();
$mail->SMTPDebug = 0; // 0 = off (for production use) - 1 = client messages - 2 = client and server messages
$mail->Host = gethostbyname("smtp.gmail.com");; // use $mail->Host = gethostbyname('smtp.gmail.com'); // if your network does not support SMTP over IPv6
$mail->Port = 587; // TLS only
$mail->SMTPSecure = 'tls'; // ssl is deprecated
$mail->SMTPAuth = true;
$mail->Username = 'mymail#gmail.com'; // email
$mail->Password = 'mypassword'; // password
$mail->setFrom($email, $name); // From email and name
$mail->addAddress('mymail#gmail.com', 'Admin'); // to email and name
$mail->Subject = $subject;
$mail->msgHTML("Message from: \n"."<h3>".$email."</h3>\n"."<h1>".$message."</h1>"); //$mail->msgHTML(file_get_contents('contents.html'), __DIR__); //Read an HTML message body from an external file, convert referenced images to embedded,
$mail->AltBody = 'HTML messaging not supported'; // If html emails is not supported by the receiver, show this body
// $mail->addAttachment('images/phpmailer_mini.png'); //Attach an image file
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->send();
// if(!$mail->send()){
// echo "Mailer Error: " . $mail->ErrorInfo;
// }else{
// echo "Message sent!";
// }
?>
You're doing some inadvisable things here.
$mail->Host = gethostbyname("smtp.gmail.com");
This sets Host to a literal IP address, and that in turn means that you will never have it match a TLS certificate name. As a result you're having to disable TLS verification, which is never a good thing. If you understand exactly why you're doing this, and what the consequences are, that's fine, but if not, you shouldn't be doing it.
There isn't any error checking in this script. I suggest starting again using the gmail example provided with PHPMailer which is much more careful.
You've discovered why sending to remote mail servers with SMTP during web form processing generally a bad idea: it's too slow, partly by design. The best way to work around this is to install a local mail server (postfix is good) and configure it as a relay to your gmail account – if you search for that you'll find plenty of examples. When that's done, you can submit messages to localhost, it will be more or less instant, and it will take care of queuing, throttling, bounces etc.
I'm using PHPMailer and I would like to save in my DB some debug info.
The code below shows how to save debug info when using an SMTP server like below:
mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->SMTPDebug = 2; //Alternative to above constant
$mail->isSMTP(); // tell the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 25; // set the SMTP port
$mail->Host = "mail.yourhost.com"; // SMTP server
$mail->Username = "name#yourhost.com"; // SMTP account username
$mail->Password = "your password"; // SMTP account password
According to the PHPMailer documentation SMTPDebug has 4 levels.
SMTP::DEBUG_OFF (0): Disable debugging (you can also leave this out completely, 0 is the default).
SMTP::DEBUG_CLIENT (1): Output messages sent by the client.
SMTP::DEBUG_SERVER (2): as 1, plus responses received from the server (this is the most useful setting).
SMTP::DEBUG_CONNECTION (3): as 2, plus more information about the initial connection - this level can help diagnose STARTTLS failures.
SMTP::DEBUG_LOWLEVEL (4): as 3, plus even lower-level information, very verbose, don't use for debugging SMTP, only low-level problems.
When I use level 2 I get Client and Server responses logged to the screen.
Is there a way to have only Server responses logged? I do not want to save Clients request too as it may have some sensitive data (The email content sent itself).
Yes. You can inject a closure that captures the debug output and writes it to your DB. There is an example in the docs:
It might be something like this (including filtering out client messages):
$mail->Debugoutput = function($str, $level) use ($db) {
if (strpos($str, 'CLIENT -> SERVER') === false) {
mysqli_query($db, "INSERT INTO maildebug SET level = '".mysqli_real_escape_string($db, $level)."', message = '".mysqli_real_escape_string($db, $str)."'");
}
};
A somewhat tidier option would be to accumulate all the debug output in a temporary variable, and only write it to the DB if there is a problem.
I'm trying to run a phpMailer function on my server (iPage) and I can't get it to work. I've tried to use gmail to make sure the script was fine and it's working perfectly. After spending more than 4 days troubleshooting with iPage live help and support ticket platform, I've decided to share my problem with you.
Here's the function I'm using :
function send_mail($email,$message,$subject) {
require_once('mailer/class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.ipage.com";
$mail->Port = 587;
$mail->AddAddress($email);
$mail->AddCC('info#m7b5.com', 'm7b5');
$mail->Username="test#m7b5.com";
$mail->Password="dsdw23dds";
$mail->SetFrom('info#m7b5.com','m7b5');
$mail->AddReplyTo("info#m7b5.com","m7b5");
$mail->Subject = $subject;
$mail->MsgHTML($message);
$mail->Send();
}
}
And now first lines of the error code :
SMTP -> FROM SERVER:220 ESMTP Sat, 04 Mar 2017 10:31:18 -0500: UCE strictly prohibited
SMTP -> FROM SERVER: 250-bosauthsmtp10.yourhostingaccount.com Hello www.m7b5.com [66.96.143.93] 250-SIZE 34603008 250-8BITMIME 250-PIPELINING 250-AUTH PLAIN LOGIN 250-STARTTLS 250 HELP
SMTP -> FROM SERVER:220 TLS go ahead
SMTP -> FROM SERVER: 250-bosauthsmtp10.yourhostingaccount.com Hello www.m7b5.com [66.96.143.93] 250-SIZE 34603008 250-8BITMIME 250-PIPELINING 250-AUTH PLAIN LOGIN 250 HELP
SMTP -> FROM SERVER:250 OK
SMTP -> FROM SERVER:250 Accepted
SMTP -> FROM SERVER:250 Accepted
SMTP -> FROM SERVER:354 Enter message, ending with "." on a line by itself
SMTP -> FROM SERVER:250 OK id=1ckBeS-0001xZ-SM
Ever faced the UCE strictly prohibited error?
Any workarounds I could use to resolve this issue?
Thanks a lot!
I am using phpmailer to send email.
When I add the list-unsubscribe the email gets delivered to all accounts, except gmail. It just gets dropped, it doesn't go into spam, it just never arrives at the gmail account. When I remove the list-unsubscribe, it successfully gets sent to the gmail account.
This is the list-unsubscribe that I am using:
List-Unsubscribe:<http://keepity.com>,<mailto:admin#keepity.com>
This is how its called in phpmailer:
$mail->AddCustomHeader("List-Unsubscribe:<http://keepity.com>,<mailto:admin#keepity.com>");
This is the full function that calls phpmailer. If I comment out the list-unsubscribe then the mail gets delivered to gmail account, otherwise it never arrives. Does anyone know why it would not be delivered?
static function phpmailer_sendmail($mail,$from,$fromAlias,$to,$replyTo,$replyToAlias,$subject,$html,$text) {
require_once (JPATH_COMPONENT.DS.'PHPMailer-master/class.phpmailer.php');
$mail = new PHPMailer(true); // by setting TRUE you enable exceptions
$mail->IsSMTP(true); // SMTP
$mail->SMTPAuth = true; // SMTP authentication
$mail->Mailer = "smtp";
$mail->Host= "xyz"; // Amazon SES
$mail->Port = 465; // SMTP Port
$mail->Username = "xyz"; // SMTP Username
$mail->Password = "xyz"; // SMTP Password
$mail->ClearAllRecipients();
$mail->ClearAddresses();
$mail->ClearCCs();
$mail->ClearBCCs();
$mail->ClearReplyTos();
$mail->ClearAttachments();
$mail->ClearCustomHeaders();
$mail->SetFrom($from, $fromAlias);
$mail->AddReplyTo($replyTo,$replyToAlias);
$mail->Subject = $subject;
$mail->IsHTML(true);
$mail->Body = $html;
$mail->AltBody = $text;
$address = $to;
$addressAlias = $to;
$mail->AddAddress($address, $addressAlias);
$mail->AddCustomHeader("List-Unsubscribe:<http://keepity.com>,<mailto:admin#keepity.com>");
$mail->Send();
}
the function addCustomHeader gets 2 arguments
and the unscribe value format should be
<email_to_unscribe#email.com>, <http://url_to_unscribe.com>
here is an example how it should be called :
$mail->addCustomHeader("List-Unsubscribe",'<admin#keepity.com>, <http://keepity.com/?email='.$address.'>');
I know this is old, but it's ranking well in Google for a search of "List-Unsubscribe" and the provided suggestion isn't quite correct.
PHPmailer addCustomHeader only takes one argument. The double quotes wrap the entire header like this.
$mail->AddCustomHeader("List-Unsubscribe: <mailto:info#example.com?subject=Unsubscribe>, <http://example.com/unsubscribe.php?mailid=1234>");
List-Unsubscribe takes 2 arguments, a mailto: and a URL that can be set up to automatically unsubscribe the email. Of course you can generate the mailid (or whatever you call the GET var) dynamically too.
I am on a shared hosting plan, and when I send emails with PHP, email clients (like Gmail) will add a little via bit to my from field, with my host's domain in there.
So instead of my emails being just from my domain:
From: me#mydomain.com
It's from two domains:
From: me#mydomain.com via host13.myhost.com
Clearly, this is confusing to people receiving email and is poor branding. Since I'm on a shared hosting plan, I don't think I'm likely to have access to the configurations settings of PHP or whatever it uses to mail. Is it possible for me to digitally sign my PHP emails, or is this not possible on shared hosting?
Here is what I'm doing now:
$header = "From: me#mydomain.com";
mail("you#yourdomain.com", "subject", "body", $header);
You can try this, you need to download the PHP Mailer class from Here and your code will be like this:
<?php
include "PHP MAILER CLASS";
$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->SMTPDebug = 1; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "example#gmail.com"; // GMAIL username
$mail->Password = "password"; // GMAIL password
$mail->AddAddress("Reciever Email", "Reciever Name");
$mail->SetFrom('Sender Email', 'Sender Name');
$mail->Subject = "Subject";
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
$mail->MsgHTML("Message Body");
$mail->Send();
} catch (phpmailerException $e) {
$e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
$e->getMessage(); //Boring error messages from anything else!
}
?>
The default mail function is at the mercy of your server setup and rarely looks like regular mail to the reciever. You should use a library either SwitfMailer or pear MAIL that can send the mail through your own mail server via SMTP. You can use your normal email account or setup a new one for your web service.