Question

On my localhost (Linux Mint OS) Swiftmailer is working fine with the following code, but whenever I move it up to my server is just hangs at the send function and then gives me an internal server error.

I currently have my email setup through Google Apps, so maybe SMTP will not work for this situation? If thats the case, how do you suggest I change this from SMTP.

Also, whenever I send an email like this, it is showing up with a from address of the one in the username area. I want it to show up with the from address in the "setFrom" function.

//Include the swiftmailer class
require_once 'comm/swiftmailer/swift_required.php';

//Create a message
//Pass it as a parameter when you create the message
$message = Swift_Message::newInstance();
$message->setSubject('My Subject');
$message->setFrom(array('noreply@domain.com' => 'No Reply'));
$message->setTo(array('me@domain.com' => 'Me'));
$message->setBody($emailContent, 'text/html');

//Create transport class and email the message
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')->setUsername('useracctname')->setPassword('password');
$mailer = Swift_Mailer::newInstance($transport);
$result = $mailer->send($message);

Thanks a lot for any help!

Was it helpful?

Solution

This might be a port problem on the server. Port 465 could be closed to prevent spamming. It could also be that the server's version of PHP lacks SSL support.

I am wondering though, could it be that I am not using the local mail server so it wont allow SMTP?

If you address gmail as explicitly as you do, it's very unlikely you're using another transport type or a different server.

Also, what about using one of the other transport types?

I think SMTP is your only option to get it running with Gmail. It could, however, be that your server is providing a mail() based service (obviously with a different sender address than GMail though). In that case, you may be able to use Swiftmailer's mail transport.

OTHER TIPS

I had the same problem : I was able to send gmail email in local (after updating that configuration : https://www.google.com/settings/security/lesssecureapps ) but not in production.

To fix my problem I've logged to my gmail account with my production ip / from my production server and answer the gmail security question.

One of the solution to log to your gmail account with your production ip, is to

  1. open an ssh tunnel (ssh -2NfCT -D 5000 yoursshuser@yourdomain.org)
  2. configure you browser to use that proxy (eg Firefox :to Preferences > Advanced > Network > Settings > Manual proxy configuration > SOCKS Hosts: localhost / Post: 5000 / SOCKS v5 )
  3. log to you gmail account as usual

The error outputed by Symfony was :

app.ERROR: Exception occurred while flushing email queue: Failed to authenticate on SMTP server with username "joe.doe" using 1 possible authenticators [] []

well, here is the solution.

if you are sending SMTP mail you should create email account at the server then use this email info at your code. the server will not send the email if you don't have valid email account to send using it when you use "from". this should be a true correct email account a fake one.

the only possible reason to send using fake account is using mail() function.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top