require("class.phpmailer.php");
$mail = new PHPMailer()
$mail->From = "sender#gmail.com";
$mail->AddAddress("recipient#gmail.com"); // name is optional
$mail->AddReplyTo("sender#gmail.com");
$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = "Here is the subject";
$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";
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
I don't know what headers i need to add, to send the email NOT as spam, and how can i use this?
//$mail->IsSMTP(); // is this necessary?
//$mail->Host = "some host ip"; // what i need to write here?
//$mail->SMTPAuth = true; // is this necessary to send email NOT as spam?
//$mail->Username = "test"; // and this?
//$mail->Password = "secret"; // and this?
for some time googling , I didn't find any clear information about how to send an email NOT as spam... any ideas?
Unfortunately, the mail server you're currently using has probably been sending out junk in the past. Are you on a shared hosting plan? Because if you are, it's possible that other websites on the same hosting plan as you have been sending out spam/suspicious/junk emails via the same the mail server. To try and avoid this issue, you should try and not use spoofed FROM headers. Unfortunately, that's unlikely to do anything if Gmail etc have already identified the mail server you're using as an origin for spam.
Make sure the From header really matches e-mail address available on the server you're sending it from - spoofing From headers (sending from host.com but saying it's from abc#otherhost.com) raises your spam score.
Also - is the HTML page well-formed to prevent being marked as spam? For example, does it have an unsubscribe link? Or isn't the subject of that mail something like "free something for you"?
I am not sure but see below URL I think it is very help full to you.
How do I prevent mails sent through PHP mail() from going to spam?
How do I prevent mails sent through PHP mail() from going to spam?
Related
So as stated in the title I wanna created a function different from mail to send mail(confusing ik)
So using mail () it sends the email from my server regardless of the headers I put so I need to create a function to send the actual email from a set email
Let's say I have an email
flameforgedinc#gmail.com
Lets say I have a bunch of emails in a mailing list
Now I have some code that's gonna use this function to email each one
So this code use's cMail ($to, $sub, $msg, $from);
And the email will appear to the user
From: flameforgedinc#gmail.com
And I actually want it to come from my email
If I use mail then it comes from my server and displays altervista00000 and I don't want the plus my server limits the mail() function to activation emails and I need to be able to send newsletters
Any ideas or workarounds??
My name is Pavel Tashev. I will try to help ;)
The easiest and more correct way from technical point of view is to use your own Mail server which hosts your email account and sends your emails. The purpose of PHP in that cases will be to tell the mail server to send email X to a list of emails Y, from an email account Z.
This will solve all your problems:
max allowed emails per hour;
sender name;
The good news is that you already have a Gmail account which is hosted by Google and you don't need to build your own mail server. You can use Google's mail server. Also, for the email sending I would advice you to use PHPMailer (url: https://github.com/PHPMailer/PHPMailer).
Here is how we can do all of this. Follow these steps:
Integrate PHPMailer in your project. If you use composer, that will be a straightforward process. If you don't, simply download the code and include this file PHPMailerAutoload.php in your project. Just follow the instructions on Github. It is really easy.
So, when you are ready with the installation of PHPMailer you must tell it to connect to your mail server. For Gmail and your email account this would look like this:
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'flameforgedinc#gmail.com';
$mail->Password = 'PUT-YOUR-PASSWORD-HERE';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('flameforgedinc#gmail.com', 'YOU CAN PUT YOUR NAMES HERE IF YOU WANT');
The final step is to set up the recipient and the content of the email:
$mail->addAddress('some.user#example.net', 'Joe User');
$mail->addAddress('seconrd.user#example.com', 'The name is optional');
$mail->addReplyTo('flameforgedinc#gmail.com', 'YOU CAN PUT YOUR NAMES HERE IF YOU WANT');
$mail->isHTML(true);
$mail->Subject = 'Here is the subject';
$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';
now you will have to send the email:
!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
I hope that will help.
We unable send an email from CRM at hotmail. We use google app as email host. Our custom applications PHP by our own developer. We able send email at every domain like yahoo, AOL and other domain except hotmail account.
We checked our PHPMailer script and also run google smtm but nothing is working. Please help me out of this issue.
<html>
<head>
<title>PHPMailer - Mail() basic test</title>
</head>
<body>`enter code here`
<?php
require_once('../class.phpmailer.php');
$mail = new PHPMailer(); // defaults to using php "mail()"
//$mail->IsHTML(true);
//$mail->CharSet = 'windows-1251';
$body = 'This is ....';
$mail->AddReplyTo("task#mytasker.com","Mytasker1");
//$mail->SetFrom('deep_m#outlook.com', 'Deep');
//$mail->SetFrom('saikat_mytasker#hotmail.com', "Saikat Mallick");
$mail->SetFrom("task#mytasker.com","Mytasker");
$address = "saikat#mytasker.com";
//$mail->AddAddress('saikat_mytasker#hotmail.com', "Saikat Mallick");
$mail->AddAddress('deep_m#outlook.com', 'Deep');
$mail->AddAddress($address, "Saikat Mallick");
$mail->Subject = "Mytasker 123 ...";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
//$mail->AddAttachment("images/phpmailer.gif"); // attachment
//$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
</body>
</html>
This is probably hotmail servers are classifying your email content or servers as spam and is auto blocked. Though this is a little off topic but may i suggest to switch to third party email senders such as mandrill or mailjet. In this way, you will mitigate the risk of your content / servers being classified / marked as spam and ensure 99.99% hitting inbox rate
I am using phpmailer() to send email from my website. But when It's sent email I see following warning message.
I can't understand why it's showing and how can I fix this error message. Can anyone tell me about it ?
Following is my code :
<?php
require_once("mail/PHPMailerAutoload.php");
$mail = new PHPMailer;
$mail->setFrom($email);
$mail->addReplyTo('toemail#gmail.com', 'First Last');
$mail->addAddress('toemail#gmail.com', 'First Last');
$mail->Subject = 'PHPMailer mail() test';
$mail->msgHTML(file_get_contents('mail/contents.html'), dirname(__FILE__));
$mail->AltBody = 'This is a plain-text message body';
$mail->addAttachment('mail/images/phpmailer_mini.png');
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
Easy, you could read about SPF DNS Record.
When you send and email, services like gmail check if the sender ip is the same that the domain of the email, for example:
You send an email as "foo#gmail.com" to "bar#hotmail.com". Your
server ip is 1.1.1.1
Hotmail receives an email from "foo#gmail.com" so check if gmail.com
ip (2.2.2.2) is the same as your server (1.1.1.1). The answer is NO,
so the email is marked as spam.
To avoid that your email will marked as spam, you could use
phpmailer using a real google account and provide phpmailer the user
and password to send the email.
I tried to explain you the situation very easy on point 2. Real situation is a bit complicated but the logic is the same, check ip sender and origin. Read about SPF (and dkim) because is what are you looking for :)
http://en.wikipedia.org/wiki/Sender_Policy_Framework
I am working with PHP Mailer to send the mails. It working fine in my localhost. And when i tested it from my Linux server, i am receiving mails to all as fine except hotmail . Please find the below code im running.
<?php require_once('PHPMailer/class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->From = "no-repy#gmail.com"; //From Address -- CHANGE --
$mail->FromName = "myname"; //From Name -- CHANGE --
$mail->AddAddress('*****#hotmail.com'); //To Address -- CHANGE --
$mail->AddAddress('*****#gmail.com');
$mail->AddReplyTo("no-reply#gmail.com", "gmail"); //Reply-To Address -- CHANGE --
$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->IsHTML(false); // set email format to HTML
$mail->Subject = "AuthSMTP Test";
$mail->Body = "AuthSMTP Test Message!";
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>
After running this im getting the response as
Message has been sent
But receiving mail to my Gmail a/c, not to the Hotmail.
Please help regarding this one.
Thanks in advance.
I had the same problem; indeed mail arrived at other destinations except hotmail.
It turns out MS*** recently decided to block emails coming from godaddy mailers (secureserver.net). And these emails are not even sent to spam/deleted folders for hotmail recipients, they are just sent to the ether. Believe it or not.
After calls and mails to both parties, where of course you get no useful info or solution, I just decided to bypass their mailers and instead use a 3rd party service: sendgrid.com. Didn't use their smtp solution, as GD seems to blocks external smtp (at least in shared hosting); but the sendgrid-php works just fine.
I've just updated a contact form to use PHPMailer to stop emails being marked as junk, with no luck.
It's a fairly straight forward setup I'm using but its still going into peoples junk mail.
Here is my script, I was wondering if anyone could tell what was wrong?
include_once('../inc/phpmailer/class.phpmailer.php');
$mail = new PHPMailer();
$name = $_POST['name'];
$email = $_POST['email'];
$body = "Name: ".$name."\r\n";
$body .= "Email: ".$email."\r\n";
$body .= "Message: ".$_POST['message'];
$mail->From = "mailer#blah.com";
$mail->FromName = "Contact BLah";
$mail->Subject = "Contact From: Blah";
$mail->Body = $body;
$mail->AddAddress("john#blah.com", "john");
$mail->AddAddress("david#blah.com", "david");
if(!$mail->Send()) {
$errorMsg .= "Error sending message, please try again later.";
} else {
$errorMsg .= "Message Sent successfully.";
}
I thought that PHPmailer normally takes care of inserting proper headers?
Any thoughts?
EDIT: Added spam score
-Spam-Status: "score=0.0 tests=none version=3.1.7 cmae=v=1.0 c=1 a=8nJEP1OIZ-IA:10
a=soyWjZv28gkhNSke5wm04A==:17 a=fqdOs_Nl9wd82e3SDigA:9 a=l-lynuxnH-gfU2bevBoA:7
a=wPNLvfGTeEIA:10 a=nymK5Bb5l1cA:10 a=_6wjLm_vFSYA:10 xcat=Undefined/Undefined"
X-Spam-Level: *
EDIT 2: I just tried the script on a different server from the clients and it has the same result. Do I have to send through the SMTP setup for it not to be classed as spam?
Some reasons your mail can get marked spam:
You're sending spam
Your IP, or a block of IPs surrounding your IP has been marked as a spam source on one or more blackhole lists
The content of the email is triggering spam filters.
The recipient has added you to their blacklist
The recipient didn't add you to their whitelist
You're sending a mixed source mail ("From: xyz#example.com", but sending it from "someotherdomain.net")
SPF records for your server are misconfigured/not configured at all
Domain keys are misconfigured/not configured at all
etc...
PHPMailer is a tool. Consider it a hammer. The hammer may have bent the nail, but only because the wielder didn't aim right.
The only way you'll solve this problem is by examining the bounce messages (if any), and whatever showed up in the recipient's mailbox. If they receive the mail, but it goes into a spam folder, then get a copy of the mail and examine its headers. Most spam filters will put their spam score/reasoning in there.
Small hint:
add in a line like so
$mail->AddReplyTo( 'mailer#blah.com', 'Contact BLah' );
It should decrease your SPAM rating significantly.
I was having the same problem using PHPMailer, and here's what fixed the problem for me: set the Sender (this is different and distinct from the "From") to a valid email account for the domain you are sending the email from. This causes PHPMailer to properly set the "envelope-from" information so that the email passes SPF and Sender-ID validation. Without doing this, the "envelope-from" is a OS user id and server combination which will not be verifiable.
Example Code:
$mail = new PHPMailer;
$mail->From = 'from_email#domain.com';
$mail->Sender = 'sender_email#domain.com';
...
It is not necessarily PHPMailer's fault, there are several possible reasons for your server to be blacklisted. You can check here to see if this happened