I am trying to get Swiftmailer to work but keep getting "recipient rejected" messages.What causes the "recipient rejected" response? Is this a response from the gmail server (gmail sensing this is SPAM)? Is there a way to overcome this? Otherwise, I will abandon Swiftmailer and try PHPMailer. I've had success with PEAR packages in the past but got tired of the configuration and was going to try Swiftmailer first...it shouldn't be this difficult right?
My Configuration:
- PHP 5.5.6
- Swiftmailer 5.0.3 (with Logger Plugin)
- Hosting by GoDaddy (yeah...I know)
Goal: Use Swiftmailer to send SMTP message from admin#mydomain.org to legit#gmail.com
(obviously the email addresses are placeholders for actual addresses)
Here is the PHP code: (same as example in Swiftmailer documentation)
<?php
require_once 'lib/swift_required.php';
$transport = Swift_SmtpTransport::newInstance('smtp.mydomain.org', 25)
->setUsername('admin#mydomain.org')
->setPassword('mypassword')
;
$mailer = Swift_Mailer::newInstance($transport);
$logger = new Swift_Plugins_Loggers_EchoLogger();
$mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($logger));
$message = Swift_Message::newInstance('Wonderful Subject')
->setFrom(array('admin#mydomain.org' => 'admin'))
->setTo(array('legit#gmail.com' => 'recipient'))
->setBody('Here is the message itself')
;
$result = $mailer->send($message);
echo $logger->dump();
?>
Here is the relevant logger info:
...
++ Swift_SmtpTransport started
...
>> RCPT TO: <legit#gmail.com>
<< 550 5.1.1 <legit#gmail.com> recipient rejected
!! Expected response code 250/251/252 but got code "550", with message "550 5.1.1 <legit#gmail.com> recipient rejected "
>> RSET
<< 250 2.0.0 OK
++ Stopping Swift_SmtpTransport
>> QUIT
Not a "real" answer, but too long for the comment box:
Is this a response from the gmail server
Yes.
recipient rejected means that, somehow, the recipient (that is, the address you're sending mail to, legit#gmail.com`) is "rejected".
This can have a number of causes
Email address doesn't exist (anymore) (quite probable)
User mailbox is full (quite probable)
The account is blocked by gmail (quite probable)
the user set a filter to explicitly reject emails from you (not sure if this can be done using gmail, but it's technical possible).
Your message is considered spam (unlikely, you would probably get a different message)
... many others...
It's somewhat unfortunate that gmail doesn't provide more info as to the cause. I can't find any documentation on gmail's error codes (550 is a generic "it failed" code), and usually these sort of messages are more verbose ...
What you could try:
Make very sure the email exists and is valid. Use a different gmail address (ie. one accessible by you) to be sure.
Check if you're blacklisted, for example using: http://mxtoolbox.com/blacklists.aspx
Try sending mail from smtp.mydomain.org, for example with the commandline mail utility (if it's a UNIX box), if this doesn't work, you know the problem is at the mail server, if it does work, you know the problem is at Swift mailer.
Related
I am using phpmailer to send mail in Yii1. System which i have developed send thousand of emails daily. Normally it is working fine how ever sometime system fails to send email. After sometime that mail was delivered successfully (if system fails to send email first time then it will try again
). I am getting different types of email error some time. Not sure how to resolved those errors:
Mailer Error:
The following From address failed: test#test.com : MAIL not accepted
from server,x.x.x.x SMTP; Client was not authenticated to send
anonymous mail during MAIL FROM
[MWHPR11CA0017.namprd11.prod.outlook.com]SMTP server error: 5.7.57
SMTP; Client was not authenticated to send anonymous mail during MAIL
FROM [MWHPR11CA0017.namprd11.prod.outlook.com]
The following From address failed:
test#test.com : MAIL not accepted from server
SMTP Error:
Data not accepted.SMTP server error: 2.1.5 Recipient OK
The following From address failed:
test#test.com : MAIL not accepted from server,354,Start mail input;
end with < CRLF >.< CRLF >SMTP server error: Start mail input; end
with < CRLF >.< CRLF > SMTP server error: Start mail input; end with
< CRLF >.< CRLF >
SMTP Error:
The following recipients failed:xxx#xxx.com
So above is the different types of errors i have got sometimes. For #5 it seems that recipient was incorrect so that one is fine. But what about the others? How to solve them?
Depending on the MTA (mail transfer agent) installed on the server, ports used and SMPT settings, you may need to create the "from" user account on the server.
If you're using SSL/TLS, make sure the digital certificate(s) exist and has not expired. Also make sure your server's OS and MTA is up to date with the latest security standards -which if not compatible with latest industry standards may cause issues with the handshake/delivery mechanism.
you can always debug with command mail on your server. But as #argon already answered, the problem is probably with SMTP server.
I warmly suggest using external email marketing service if you are sending
thousand of emails daily.
Your server reputation will only get worse and will go straight to spam or rejected by SMTP (as in your case).
Okay, I'm at my whit's end here. I have a client whose site is hosted on GoDaddy and that uses Outlook. I've written a PHP script to send mail to one of their domain e-mail addresses from a contact form on their website.
I can get this e-mail to send to every single service except outlook/exchange/live/microsoft accounts.
I read that using PHPMailer was a good idea, so this is what I'm currently using to send mail:
//$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 2;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "a2plcpnl0287.prod.iad2.secureserver.net";
$mail->Port = 465;
$mail->Username = "test#alamohomefinance.com";
$mail->Password = "xxxxxxx";
$mail->SetFrom('yourname#yourdomain.com', 'First Last');
$mail->AddReplyTo("name#yourdomain.com","First Last");
$mail->Subject = "PHPMailer Test Subject via smtp (hotmail), basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML($body);
$address = "jakerevans2#live.com";
if(!$mail->Send()) {
error_log("Error from calculator!". $mail->ErrorInfo);
} else {
error_log("Success from calculator!");
}
This e-mail gets sent to my gmail account and some others, but not to my .live account or my client's Outlook address.
I've tried everything I've found on the internet so far, nothing is working. Any ideas or thoughts anyone?
Thanks!
EDIT:
The Godaddy server has an SPF record that reads: v=spf1 include:spf.protection.outlook.com -all
I've created a DKIM key from https://www.port25.com/dkim-wizard/ and added a DKIM TXT record to GoDaddy, with the following details:
Host: key1._domainkey.alamohomefinance.com
TXT Value: k=rsa\; p=MIIBIjA...
I've added a DKIM record, with the following details:
Name: _dmarc.alamohomefinance.com
TXT Value: v=DMARC1; p=quarantine; sp=none; ruf=mailto:user#example.com; rf=afrf; pct=100; ri=86400
Am testing now to see if these changes make a difference...
First up, you should look at the PHPMailer troubleshooting guide, which has a little section on GoDaddy, and many other problems.
You will get much better feedback on what's going on if you enable debug output of server messages, so set SMTPDebug = 2, and see what it says.
GoDaddy is known to block outbound SMTP, and generally will either simply fail to connect (see many questions on SO about that), or cause TLS verification failures as you get redirected transparently to their mail servers.
In your code you've got the smtp.live.com Host, but this username:
$mail->Username = "a2plcpnl0287.prod.iad2.secureserver.net"
secureserver.net is the domain used for GoDaddy's mail servers, and that user name is the name of an actual GoDaddy mail server, so it seems very unlikely that you should be using it as a user id for live.com, especially since GoDaddy will be rotating mail servers frequently, so you're unlikely to get the same one every time - is that really your login ID for live.com?
I'm also suspicious of the phrasing of your question: you do not need to connect to live.com to send email to live.com - there's nothing stopping you sending to a live.com address from a connection through gmail, so it sounds like you may have a conceptual issue. The Host, Username and Password properties are for the mail server that you send out through, not that you are sending mail to.
As I said, normally GoDaddy doesn't allow remote SMTP at all, so I'm very surprised if you've had it working without using a GoDaddy mail server, so I suspect you've had something else work, not what you think.
I can also see you've based your code on an obsolete example, so make sure you're running the latest PHPMailer.
Update:
I noticed something critical. The code does not call $mail->isSMTP();. This means that it's not using SMTP at all, it's using the default mail() function, and as such none of the SMTP config makes any difference at all. The message will be submitted to your local mail server, which will then relay through GoDaddy's server. Look in your mail server's log file to see what's happening, usually in /var/log/mail.log or similar.
Check your server ip on http://mxtoolbox.com/blacklists.aspx . I've noticed Microsoft is very picky about blacklisting. I've had this issue with a brand new I.P addresses that were acquired with an apparent bad rep. If your on godaddy on a shared account ip it's very likely either the ip or entire subnets are blocked by default.
My clients hosting service isn't accepting emails sent from the website that doesn't have "-f" at the start of the FROM address. This related to a recent outgoing SPAM filter they added.
Official response is:
“senders envelope of data” is missing certain elements
I use phpmailer, everything was working fine until now using SMTP authentication.
But now with phpmailer, this DOESN'T work
$mail->From = 'me#test.com';
Also doesn't work
$mail->From = '-f me#test.com';
Its invalid obviousdly, not a good looking email address.
I CAN get mail to actually send like this:
mail('me#test.com', 'the subject', 'the message', null, '-f me#test.com');
But that isn't phpmailer, this is the garden variety php function. So im trying to make PHPmailer add "-f " to the FROM automatically somehow.
Should I be adjusting the class files to somehow get around that? Stuck!
You've got your transports mixed up. -f in the mail() function is an additional parameter passed to the underlying sendmail binary that sets the envelope sender of the message (and officially it should not have a space after it, like -fme#test.com). However, it does not apply when you are sending via SMTP because you get control over that parameter with the Sender property. You should do this:
$mail->Sender = 'me#test.com';
If you send using SMTP it will use that as the envelope sender (as the content of the SMTP MAIL FROM command), and if you send via isMail() or isSendmail() transports, it will set the sender via the -f property.
Also make sure you're using the latest PHPMailer from GitHub.
I asked a similar question earlier, but the context has changed a bit. I want to use swiftmailer to send an email in Symfony 2. The problem is I'm using the gmail SMTP server, and so when my message arrives, my email client shows it from gmail.com, rather than mydomain.com. How can I fix this?
$message = \Swift_Message::newInstance()
->setSubject('Hello Email')
->setFrom(array('digest#mydomain.com' => "Digest"))
->setSender(array('digest#mydomain.com' => "Digest"))
->setCharset('iso-8859-1')
->setContentType('text/html')
->setTo('myemail#gmail.com')
->setBody($this->renderView('email.html.twig', array()));
$this->get('mailer')->send($message);
The Gmail SMTP server only allows you to send mail using the email address you're aithenticating with. So if you configured Symfony with
mailer_transport: gmail
mailer_user: myemail#gmail.com
mailer_password: ******
All your messages we'll look like they're from myemail#gmail.com
What you can do maybe is use another smtp server that is more flexible in the types of From addresses they will allow. If you are on a local development server, you could use your ISP's SMTP server, or use one of the various email as a service provider, such as Sendgrid, Mailjet or postmarkapp
They all allow you to send messages from any address you can prove ownership of, after some configuration steps.
One thing that may be worth trying also if you really want to use the gmail smtp server, is to define your from address in your "Send mail as" Gmail configuration (in Settings -> Accounts). This will let your app send email using the configured adresses in the From: field.
I am using Swiftmailer to send emails with SMTP
I need to get response from SMTP, but what I am trying is not working. Is it even possible?
I tried an invalid email: dima44324d#vdaszdsd1dw.com - on the code below, which does not return errors
if (!$mailer->send($message, $fails))
{
echo "Failures:";
print_r($fails);
return false;
}
return true;
P.S. I don't want to use PhpMailer because I have other issues with it.
Remember that Swiftmailer simply hands the email over to an SMTP server. It does not actually deliver it. It's not Swiftmailer's job to determine if the email address you're telling it to send to is valid or not. As long as the address conforms to RFC822 standards, it'll be accepted by Swiftmailer, and be accepted by whatever SMTP server you're using.
It's only when that SMTP server attempts to actually DELIVER the email to the invalid hostname that you'll get a failure. By that point, Swiftmailer's already disconnected and reported success - it has accomplished its mission. The failure has occured farther down the line, outside of Swiftmailer's view.