Phpmailer not in Hotmail Inbox or Spam? - php

So i thought that if you send email to hotmail it would at least arrive in spam but in this case it does not. So have i done something wrong in this code below? I tested the same code with Gmail and it works Perfectly. Sure i think its related to Hotmail Filters.
Things to note, I have setup the email address on my domain and i have an SPF Record setup.
What could be wrong? And how can i check it?
Current PHP:
<?php
require 'PHPmailer/PHPMailerAutoload.php';
$mail = new PHPMailer(true);
try {
$mail->SMTPDebug = true;
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "smtpout.secureserver.net"; // sets the SMTP server
$mail->Port = 26; // set the SMTP port
$mail->Username = "username"; // SMTP account username
$mail->Password = "password"; // SMTP account password
$mail->setFrom('email', 'Immortal Insurance');
$mail->AddAddress('sendtoemail');
$mail->AddAddress('sendtoemail');
$mail->Body = 'This is a test Email';
$mail->AddAttachment('tosend/policy.pdf');
$mail->Send();
echo "Message Sent OK<p></p>\n";
} catch (phpmailerException $e) {
echo $e->errorMessage();
} catch (Exception $e) {
echo $e->getMessage();
}
?>

Related

Mass mails not sent using PHPMailer

I need to send over 1000 mails and I am using PHPMailer for it.
I am sending mails as HTML and using SMTP.
My code looks like:
while($count<1000)
{
try{
if($count%20==0)
{
$mail = new PHPMailer;
$mail->SMTPDebug = true; // Enable verbose debug output
//$mail->SMTPDebug = 3;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'localhost'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'username'; // SMTP username
$mail->Password = 'password'; // SMTP password
//$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
//$mail->Port = 587; // TCP port to connect to
$mail->Timeout = 200;
$mail->SMTPKeepAlive = true;
$mail->setFrom(username, sender);
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
}
$msg = htmlspecialchars_decode($message);
$msg = substr($msg,0,-14);
$mail->Body = $msg;
$mail->addAddress(emails);
if($mail->send())
{
$flag="1";
}
$count++;
$mail->ClearAddresses();
$mail->Smtpclose();
}catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
}
Atmost 20 mails are only sent at a time.
Is it because mails may contain spam?
Suggest you to delay your loop, you can use sleep.
I think you can send 5 per second with no problem, but you need to check with your email provider.

Cannot set Custom Sender email using PHPMailer and smtp.gmail.com

I am using PHPMailer and smtp.gmail.com to send emails to my users.
Emails are sent, no problem with that, but on the client side, in the sender email address, there is showing my servers host email address, not my email address that is set with PHPMailer->SetFrom(). I want to set my email address as sender email.
I'm using php 5.4 & PHPMailer 5.2.4
My code is given below :
<?php
require_once('class.phpmailer.php');
$mail = new PHPMailer(true);
try {
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->Username = "myemail#gmail.com";
$mail->Password = "PASSWORD";
$mail->AddAddress('receiver#email.com', 'John Doe');
$mail->SetFrom('myemail#email.com', 'My Name');
$mail->addReplyTo('myemail#gmail.com', 'My Name');
$mail->Subject = 'PHPMailer Subject';
$mail->MsgHTML('This is the body');
$mail->Send();
echo "Message Sent";
} catch (phpmailerException $e) {
echo $e->errorMessage();
} catch (Exception $e) {
echo $e->getMessage();
}
?>
This is a gmail limitation - it does not let you set arbitrary from addresses, though you can set fixed aliases in your gmail preferences. This is covered in the PHPMailer documentation. It's also a reasonable restriction - otherwise you're probably forging the from address. You can always set a reply-to address if it's reply routing you're concerned about.

Issue with Moving phpmailer Page from Localhost to Server

I have been developing a page that will automatically send emails from a Gmail account to mail accounts of various origin for specific users of my site. I have this working perfectly on Localhost. The mails are received by the users and also deposited in the "Sent Items" of the Gmail account.
However, as soon as I migrate this to the server we are using it no longer works. The code is as follows :-
$mail = new PHPMailer();
try
{
$mail->CharSet = "UTF-8";
// telling the class to use SMTP
$mail->IsSMTP();
// enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPDebug = 0;
// enable SMTP authentication
$mail->SMTPAuth = true;
// sets the prefix to the servier
$mail->SMTPSecure = "tls";
// sets GMAIL as the SMTP server
$mail->Host = "smtp.gmail.com";
// set the SMTP port for the GMAIL server
$mail->Port = 587;
// GMAIL username
$mail->Username = "xxxxxxx#gmail.com";
// GMAIL password
$mail->Password = "P4ssw0rd";
//Set reply-to email this is your own email, not the gmail account
//used for sending emails
$mail->SetFrom($from);
$mail->FromName = "XXX";
$mail->AddReplyTo('xxxxxxx#gmail.com' , 'XXX');
// Mail Subject
$mail->Subject = $subject;
//Main message
$mail->MsgHTML($message);
$mail->AddAddress($to, "");
$mail->Send();
}
catch (phpmailerException $e)
{
echo $e->errorMessage(); //Pretty error messages from PHPMailer
}
catch (Exception $e)
{
echo $e->getMessage(); //Boring error messages from anything else!
}
Setting the Debug to 1 on localhost produces the expected errors if something goes wrong. However, nothing seems to happen on the Server. Please help.

PHPMailer not sending, but no errors

I created a php application at dan.creativeloafing.com. This just takes form data and builds an html page with it, then emails the contents of that page to dan#creativeloafing.com. A couple days ago, it stopped working. I have been trying to figure this out ever since. I was using the mail() php function and have switched it over to the PHPMailer Library. This is supposedly sending the emails and I get confirmation, but nobody ever recieves the email and I get no bounceback or any errors. This is the jist of the code:
//PHPMailer
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'relay-hosting.secureserver.net'; // Specify main and backup server
$mail->Port = 25;
$mail->SMTPAuth = false; // Enable SMTP authentication
$mail->SMTPSecure = 'tsl'; // Enable encryption, 'ssl' also accepted
$mail->Username = 'dan#omgsurvey.com'; // SMTP username
$mail->Password = '*******'; // SMTP password
$mail->SMTPDebug = 0;
$mail->WordWrap = 50;
$mail->From = 'dan#omgsurvey.com';
$mail->FromName = 'DAN Application';
$mail->addAddress('dan#creativeloafing.com'); // Name is optional
$mail->addReplyTo($repEmail);
$mail->addCC('david.miller#creativeloafing.com');
$mail->isHTML(true);
$mail->Subject = "New DAN Request: ".$campaignName;
$mail->msgHTML(file_get_contents('./tmp/DAN_REQUEST_'.$specialString.$randomNumber.'.html'));
if(!$mail->send()) {
echo '<br />Proposal could not be sent.<br />';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
} else {
echo 'Proposal has been sent';
}
The script always reaches 'Proposal has been sent.' too. This is driving me crazy!
So what was happening here is that godaddy was blocking emails that included my domain name in them. I am not sure if this was a spam issue, but they are currently looking into it. I have gotten the emails to send using a simple mail() function and by removing any references to omgsurvey.com in the email. Silly, this mail was only ever sent to two email addresses!
Isn't:
$mail->SMTPSecure = 'tsl';
supposed to be:
$mail->SMTPSecure = 'tls';
Use try...catch and PHPMailer(true); https://github.com/Synchro/PHPMailer/blob/master/examples/exceptions.phps
//Create a new PHPMailer instance
//Passing true to the constructor enables the use of exceptions for error handling
$mail = new PHPMailer(true);
try {
mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'relay-hosting.secureserver.net'; // Specify main and backup server
$mail->Port = 25;
$mail->SMTPAuth = false; // Enable SMTP authentication
$mail->SMTPSecure = 'tsl'; // Enable encryption, 'ssl' also accepted
$mail->Username = 'dan#omgsurvey.com'; // SMTP username
$mail->Password = '*******'; // SMTP password
$mail->SMTPDebug = 0;
$mail->WordWrap = 50;
$mail->From = 'dan#omgsurvey.com';
$mail->FromName = 'DAN Application';
$mail->addAddress('dan#creativeloafing.com'); // Name is optional
$mail->addReplyTo($repEmail);
$mail->addCC('david.miller#creativeloafing.com');
$mail->isHTML(true);
$mail->Subject = "New DAN Request: ".$campaignName;
$mail->msgHTML(file_get_contents('./tmp/DAN_REQUEST_'.$specialString.$randomNumber.'.html'));
$mail->send();
echo 'Proposal has been sent';
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
Thinking send() should be Send()
if(!$mail->Send()) {

PHPMailer not sending CC or BCC

I have been testing the following code for hours. The email will send to the addresses added through $mail->AddAddress() and in the received email it states the cc but the person cced does not receive the email. I have looked everywhere and can not find a solution to why this is happening. I have run tests and all variables are being submitted to this code properly.
My server is running Linux Red Hat
My Code:
require_once('../smtp/class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$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 = 0; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls"; // sets the prefix to the server
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = $port; // set the SMTP port for the GMAIL server 465 or 587
$mail->Username = $username; // GMAIL username
$mail->Password = $password; // GMAIL password
// Add each email address
foreach($emailTo as $email){ $mail->AddAddress(trim($email)); }
if($cc!=''){ foreach($cc as $email){ $mail->AddCC(trim($email)); } }
if($bcc!=''){ foreach($bcc as $email){ $mail->AddBCC(trim($email)); } }
$mail->SetFrom($emailFrom, $emailName);
$mail->AddReplyTo($emailFrom, $emailName);
$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($content);
// $mail->AddAttachment('images/phpmailer.gif'); // attachment
// $mail->AddAttachment('images/phpmailer_mini.gif'); // attachment
$mail->Send();
echo'1';exit();
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
Old question, but I ended up here looking for an answer. Just learned elsewhere that those functions AddCC and AddBCC only work with win32 SMTP
Try using:
$mail->addCustomHeader("BCC: mybccaddress#mydomain.com");
See http://phpmailer.worxware.com/?pg=methods
Hope this helps someone, cheers!
$address = "xxxxx#gmail.com";
$mail->AddAddress($address, "technical support");
$address = "yyyyyy#gmail.com";
$mail->AddAddress($address, "other");
$addressCC = "zzzzzz#gmail.com";
$mail->AddCC($addressCC, 'cc account');
$addressCC = "bcc#gmail.com";
$mail->AddBCC($addressCC, 'bcc account');

Categories