开发者

PHP SwiftMailer Localhost Test Setup

开发者 https://www.devze.com 2023-01-31 21:34 出处:网络
I just started learning how to use SwiftMailer and I am having trouble sending a simple test message from my localhost. Below is the 开发者_开发问答code that I am trying to use.

I just started learning how to use SwiftMailer and I am having trouble sending a simple test message from my localhost. Below is the 开发者_开发问答code that I am trying to use.

//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('myemail@domain.com' => 'My Name'));

$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 25);
//Supposed to allow local domain sending to work from what I read
$transport->setLocalDomain('[127.0.0.1]');

$mailer = Swift_Mailer::newInstance($transport);
//Send the message
$result = $mailer->send($message);

Here is part of my error message,

Warning:  fsockopen() [<a href='function.fsockopen'>function.fsockopen</a>]:php_network_getaddresses: getaddrinfo failed: Name or service not known in /path/Swift/Transport/StreamBuffer.php

Update

I got it to work using gmail. I changed the Swift_SmtpTransport line to the following,

$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')->setUsername('username')->setPassword('password');


localhost is an alias for current machine (in this case, the machine PHP runs on). If you really want to send mail with localhost you have say so:

$transport = Swift_SmtpTransport::newInstance('localhost', 25);

... but you also need to install and configure your own mail server. If you don't know what's this all about, I suggest you use your mail provider's SMTP server.

0

精彩评论

暂无评论...
验证码 换一张
取 消