I'm using PHPmailer to send an email from a website to the website owner. It works fine to some addresses (e.g. my Gmail account), and it used to work to the owner's address, but he's recently changed from POP to IMAP and now he doesn't receive emails from the website. He does receive emails from other sources. This is the code:
$mail = new PHPMailer(true);
try {
$mail->AddAddress($to, 'Example To');
$mail->SetFrom('example#example.com', 'Example');
$mail->AddReplyTo('example#example.com', 'Example');
$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);
$mail->Send();
//echo "Message Sent OK</p>\n";
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
Any advice much appreciated.
Thanks!
G
That has nothing to do with the PHP code. The IMAP protocol is just responsible for fetching the mails from the server as a user (with IMAP the mails stay on server ... you have an open stream for a long time ...).
So: did he switch to another email provider? Maybe it is in spam. Check the maillog! ;-)
Related
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 building a website for a group of kitchen chefs that allows new members to subscribe without any action from the owner.
When subscribing, new users should receive an e-mail with an activation link, in order to validate their address.
In the beginning I was using the function mail(), but a few addresses weren't receiving anything from the website, so I switched to php mailer.
php mailer code (no errors shown during execution, before I had echoes to check)
require_once ('layout/phpmailer/class.phpmailer.php');
$mail = new PHPMailer(true);
try {
$mail->AddReplyTo("$NoreplyMailURL","$NoreplyMailNAME");
$mail->AddAddress($mdest);
$mail->SetFrom("$NoreplyMailURL","$NoreplyMailNAME");
$mail->AddReplyTo("$NoreplyMailURL","$NoreplyMailNAME");
$mail->Subject = "$mobj";
$mail->AltBody = strip_tags ($mmex); // optional - MsgHTML will create an alternate automatically
$mail->MsgHTML($mmex);
$mail->Send();
}catch (phpmailerException $e) {
} catch (Exception $e) {
}
$NoreplyMailURL is the (existing) web site e-mail address
$NoreplyMailNAME is something like "Chef Enrico"
$mobj is a sentence like "new password for our website" or "account activation link"
$mmex is the message text formatted in html
Gmail, some hotmail and other users are receiving our e-mails,
some hotmail, bluewin.ch and libero.it are not.
Do you have any suggestions on how to make this code stronger? Is it possible that if receiving providers does not support HTML formatting, the e-mail is not shown? I guess they should see all tags if that was the case, am I wrong?
Thank you very much in advance!
I use PHPMailer to send some email to one ore more detinations.
However I encountered a problem. Here comes:
This is my code:
$mail2->AddAddress($cliemail);
$mail2->AddCC('important#destination.com');
$mail2->SetFrom('important#destination.com', "...");
$mail2->AddReplyTo('important#destination.com', "...");
$mail2->Subject = 'Email subject... '.$wnume;
$mail2->AltBody = 'To be able to see this email please...';
$mail2->MsgHTML(file_get_contents('contents.html'));
$mail2->AddAttachment('teste/quiz.pdf'); // attachment
$mail2->Send();
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
So, my email must be sent from important#destination.com (it is another email of course)
And it gets sent to $cliemail, but it does not arrive to the CC (important#destination.com)
So apparently I cannot send an email to myself... Is this normal?
What could be the cause?
I tried to remove the AddCC and try to simply send the email directly to important#destination.com but it still does not arrive.
Is this some setting in my email account that I must do in order to be able to receive an email from myself?
So:
When I send the email to a third party email address using the above
code, it works
When I send the email to myself (the sender) (the same address that is the "SetFrom") it does not arrive
Even if I set the CC with my address, it still does not arrive, while it arrives at the main destination address ($cliemail)
Please help
I am new to use phpmailer for sending bulk mails.
The execution stops and shows error if send() fails.
Is there any way to skip the error and continue with next email id.
I am using email id's from database.
You Can Catch Exception Mechanism, to continue with next Mail with appropriate logic
Posted by Phil
PHPMAiler uses Exceptions. Try to adopt the following
require_once '../class.phpmailer.php';
$mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch
try {
$mail->AddReplyTo('name#yourdomain.com', 'First Last');
$mail->AddAddress('whoto#otherdomain.com', 'John Doe');
$mail->SetFrom('name#yourdomain.com', 'First Last');
$mail->AddReplyTo('name#yourdomain.com', 'First Last');
$mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
$mail->MsgHTML(file_get_contents('contents.html'));
$mail->AddAttachment('images/phpmailer.gif'); // attachment
$mail->AddAttachment('images/phpmailer_mini.gif'); // attachment
$mail->Send();
echo "Message Sent OK\n";
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
use can use phplist for bulk mailing with PHP mailer or without
click Here for more
In PHP, you can suppress error display by adding # to the function. This will usually prevent the error from being displayed.
For your situation, you can put the code in try..catch. In the catch section, check if the all the emails have been sent; if not, just continue with the next one. This also means that you need a way to track the total emails and the number of emails completed.
Hope this helps.
I've used two PHP email scripts and routing it through my SMTP server, when I do this though it sends two of the same email.
When I use mail() this doesn't happen, but I'd much rather use SMTP.
Any ideas why this may be occuring?
If you're setting the 'To' and/or 'Recipient' header multiple times, the SMTP server could interpret that as separate e-mail address, thus you'll receive the multiple e-mails.
I'd recommend using the PEAR Mail class. Very simple to use, and handles much of the work for you. It supports multiple backends including SMTP. Likewise, if you want to expand your class to send HTML emails, the Mail_Mime class handles this very nicely, providing methods to set the plain-text body and the HTML body (in case the recipient doesn't support HTML).
So if you're only using PHPMailer without editing it's code, it's not your script's fault. Maybe check your SMTP server's configuration?
function send_email($from, $fromname, $to, $subject, $body, $alt = '')
{
require_once('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->Host = 'localhost'; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
//$mail->AddReplyTo($from, $fromname);
$mail->AddAddress($to);
$mail->SetFrom($from, $fromname);
$mail->Subject = $subject;
//$mail->AltBody = $alt; // optional - MsgHTML will create an alternate automatically
$mail->MsgHTML($body);
$mail->Send();
echo 'Message Sent OK';
}
catch (phpmailerException $e)
{
echo $e->errorMessage(); //Pretty error messages from PHPMailer
}
catch (Exception $e)
{
echo $e->getMessage(); //Boring error messages from anything else!
}
}
That's the current function so far
Based on your code, if it's the class which is at fault, you'd expect to get 'Message Sent OK' twice (I can't see why that would happen though). If you don't, then I'd be looking at your SMTP server (maybe via a call to support).
I'm assuming you've disabled Reply-to to rule it out as a cause in this case? Note: I'm not suggesting that would affect anything (other than you likely being classified as spam).
Incidentally, I moved from PHPMailer to Swift Mailer some time ago & have never looked back. If you don't get any joy from support then I'd try at least testing with Swift Mailer.
I agree with what da5id said, why dont you take the second error message out. Further have you checked the receiver whether they REALLY get 2 messages?