I know this question has been asked before but my issue is a bit different. I use the php mailer to send a bulk of mails in a loop to customers from the database. In the body of the mail when there's no html stuff like body = "hello" the emails get delivered to the normal inbox. However, when I use html tags in $mail->Body then the email goes to spam. The code I use:
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'someone'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'someemail.com'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls';
$mail->From = 'someemail.com';
$mail->FromName = 'Mailer';
#$mail->addAddress($email); // Name is optional
$mail->addAddress('someemail.com');
$mail->AddEmbeddedImage('rr.jpg', 'logoimg', 'rr.jpg');
$mail->AddEmbeddedImage('bottom.gif', 'bottomimg', 'bottom.gif');
$mail->WordWrap = 100; // Set word wrap to 50 characters
$mail->isHTML(true); // Set email format to HTML
$username = "123";
$mail->Subject = 'Welcome';
$mail->Body = "Hello, welcome"
$mail->AltBody = 'Welcome ';
$mail->send()
The issue is only with gmail. All other major mail providers such as yahoo, hotmail and live are fine. The emails go to inbox. It may be because I use quite a lot of html, colors etc in the email. But I don't know why gmail moves the mail to spam simply because it looks like many other spam mails. Is there any solution?
Related
I am using the following code to send emails using phpmailer 6:
$mail->isSMTP();
$mail->Host = 'myhost';
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Username = 'email#mydomain.com';
$mail->Password = 'password';
$mail->Port = '587';
$mail->ContentType = 'text/plain';
$mail->IsHTML(false);
$mail->setFrom('email#mydomain.com');
$mail->addReplyTo($_POST['email'], $_POST['name']);
$mail->addAddress($to);
$mail->Subject = $_POST['subject'];
$mail->Body = "...";
$mail->send();
The email sends successfully to our company, however it always says it is from email#mydomain.com, which makes it hard for staff to find specific emails in their inbox. In the form, the user provides their name and email so ideally I'd like it to appear in Outlook as being sent from John Doe (jdoe#gmail.com) rather than email#mydomain.com.
In old versions of webforms I use to do this by setting the from address however now that doesn't seem to be possible because it's considered spoofing.
Is there a way to accomplish this?
Simply add in the name as the second parameter in your setFrom. See the example below:
$mail->setFrom('darth#empire.com', 'Darth Vader');
It'll then appear as you want it!
I am working to send email via the PHP Mailer class. I tried many times but I'm getting spam email every time. I want to use it for whatuser. I am using the PHP Mailer class and get spam emails. Please help, my code is the following:
require_once("PHPMailer-final/class.phpmailer.php");
$admin_email="support#example.com";
$admin_email_caption="example.com";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "mail.example.com"; // SMTP servers
$mail->Port = 26;
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Mailer = "smtp";
$mail->Username = "support#example.com"; // SMTP username
$mail->Password = "123456789"; // SMTP password
$subject=$subject_mem;
$cs_email=$to_mem;
$body_admin = $body_mem;
$headers ="From:".$admin_email_caption."<".$admin_email.">\nReply-To:".$admin_email."\nContent-Type:text/html";
$mail->From = $admin_email;
$mail->FromName = $admin_email_caption;
$mail->AddReplyTo($admin_email);
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body = $body_admin;
$mail->AltBody = "This is alt body.";
$mail->AddAddress($cs_email);
if(!$mail->Send())
#mail($cs_email,$subject,$body_admin,$headers) or die("not send");
//echo $cs_email."<br>";
$mail->ClearAddresses();
$mail->ClearAttachments();
$mail=NULL;
You should check your SMTP configurations.
Maybe SMTP configuration is not correct. For this reason your mail() function is working. And mail() function have some missing headers. Example charset. Missing or invalid header is another reason for getting mail in spam
Here is the details about PHPMailer Configurations
Uncomment the line //$mail->SMTPDebug = 3; for Debugging your SMTP configurations
I use phpmailer to send an email with a hyperlink on its body. I have this code:
$body = "<a href='".DIR."activate.php?x=$id&y=$activasion'>".DIR."activate.php?x=$id&y=$activasion</a>";
require('classes/PHPMailerAutoload.php');
$mail = new PHPMailer;
$mail->CharSet = "UTF-8";
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = SMTP_HOST; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = SMTP_USER; // SMTP username
$mail->Password = SMTP_PASSWORD; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
$mail->setFrom(SMTP_USER);
$mail->addAddress($to); // Add a recipient Name is optional
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AltBody = $altbody;
if(!$mail->send()) {
echo $mail->ErrorInfo;
}
When I send the email to a Gmail address and open it in Gmail the hyperlink looks fine (I can click on the link and redirect to the page).
But when I send it to Outlook the hyperlink looks like this:
[my.domain.com/activate.php?x=52&y=aa1fdf437c526ee219decc1ea72fc266]my.domain.com/activate.php?x=52&y=aa1fdf437c526ee219decc1ea72fc266
Any ideas on what might be wrong?
E-mail clients have different rendering engines.
It appears that gmail will render a link without the http:// or https:// protocol.
Outlook may still require it.
Try using a protocol-less (aka scheme-less) URL: //
$body = "<a href='//".DIR."activate.php?x=$id&y=$activasion'>".DIR."activate.php?x=$id&y=$activasion</a>";
EDIT:
Note from #Synchro in the comments:
Anonymous/relative protocol URLs are a bad idea in email because
unless you're in a webmail client, you have no base protocol to be
relative to, and so they just break. Make it explicit and it will work
everywhere, and these days it's hard to find a good excuse not to use
https.
I am working on ticketing system in PHP. I convert mails to tickets. When a user replies to the mail from the Ticketing system, it is sending the mail to the customer as a new mail. No message/mail threading.
I think, my problem is related to the added ticket id at the end of the subject. (e.g. Subject: Installation Problem [#EMSY45])
I have passed the Message ID and References in the Header
I am using PHPMailer to send the mail.
Here is my code:
$mail = new PHPMailer();
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = str_replace('/', '', $host); // Specify main and backup SMTP servers
if($outgoing_server_details['smtp_auth'] == 1)
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = $outgoing_server_details['server_username']; // SMTP username
$mail->Password = $outgoing_server_details['server_password']; // SMTP password
$mail->SMTPSecure = $protocol; // Enable TLS encryption, `ssl` also accepted
$mail->Port = $port;
$mail->setFrom($outgoing_server_details['from_email_field'], $from_name);
$mail->addAddress($data['_from'], $to_name); // Add a recipient
$mail->addReplyTo($outgoing_server_details['from_email_field'], $reply_to_name);
$message_id = $data['message_id'];
$mail->AddCustomHeader('In-Reply-To', $message_id);
$mail->AddCustomHeader('References', $message_id);
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $data['subject'];
$mail->Body = $mail_content;
$mail->send();
If you need to add ticket ID in the end Subject of the E-Mail then try this.
$mail->Subject = "Installation Problem [".$message_id."]";
OR
$mail->Subject = $data['subject'].$message_id;
And one more Correction
$mail->isHTML(true);//should always come after the Body is set.
i.e.,
$mail->Subject = $data['subject'].$message_id;
$mail->Body = $mail_content;
$mail->isHTML(true);
$mail->send();
I got a contact us page using PHP. Like all contact us, after someone clicking send, it will send a warning to my email.
The problem is it doesn't work. The script works perfectly in my localhost, it doesn't work only on the server and it doesn't show any error.
$default_path = get_include_path();
set_include_path(dirname(__FILE__)."/../");
require_once("extensions/PHPMailer/class.phpmailer.php");
set_include_path($default_path);
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->SMTPSecure="ssl";
$mail->Host="smtp.gmail.com";
$mail->SMTPDebug =0;
$mail->Port=465;
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = Yii::app()->params['sender_email']; // SMTP username
$mail->Password = Yii::app()->params['sender_password']; // SMTP password
$webmaster_email = Yii::app()->params['webmaster_email']; //Reply to this email ID
$mail->From = $email_address;
$mail->FromName = "Webmaster";
$mail->AddAddress($email_address,"");
$mail->AddReplyTo($webmaster_email,"Webmaster");
$mail->WordWrap = 70; // set word wrap
//$mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment
//$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // attachment
$mail->IsHTML(true); // send as HTML
$mail->Subject = $mailcontent->subject;
$mail->Body = $mailcontent->body;
//$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
$mail->Send();
I think it's because of server misconfiguration(this is my first time settings a server), but i didn't know what i did wrong.
The firewall already set to allow every traffic, so it's not firewall problem.
No error and no results makes me very confused.
Okay, after I checked everything, it turns out google block my email access from the server because of suspicious activity.
To unblock this, you need to visit this page : https://accounts.google.com/DisplayUnlockCaptcha
and then run the script again.