无法让 xammp 通过 PHP 发送电子邮件
尝试让我的 php 脚本发送电子邮件时遇到大问题。在我的 Mac 上使用此脚本:
<?php
require_once 'lib/swift_required.php';
$image = file_get_contents("php://input");
$attachment = Swift_Attachment::newInstance($image, 'submission.jpg', 'image/jpg');
$message = Swift_Message::newInstance()
/*Give the message a subject*/
->setSubject('Your subject')
/*Set the from address with an associative array*/
->setFrom(array('email'=>'Name'))
/*Set the to addresses with an associative array*/
->setTo(array('email'))
/*Give it a body*/
->setBody('Email');
$message->attach($attachment);//<--When the attachment above is commented out, so is this
$transport = Swift_SendmailTransport::newInstance();
$mailer = Swift_Mailer::newInstance($transport);
$mailer->send($message);
?>
电子邮件发送正常,附加图像,非常棒。然而这在 Windows 上不起作用。我读过 Windows 没有邮件服务器,所以最近几天我一直在与 hmailserver、mercury、mailsender 等进行斗争,试图发送电子邮件。 我从 swiftmailer 收到一个奇怪的错误:
Fatal error: Uncaught exception 'Swift_TransportException' with message 'Process could not be started [The system cannot find the path specified. ]' in C:\xampp\htdocs\lib\classes\Swift\Transport\StreamBuffer.php:268 Stack trace: #0 C:\xampp\htdocs\lib\classes\Swift\Transport\StreamBuffer.php(66): Swift_Transport_StreamBuffer->_establishProcessConnection() #1 C:\xampp\htdocs\lib\classes\Swift\Transport\AbstractSmtpTransport.php(101): Swift_Transport_StreamBuffer->initialize(Array) #2 C:\xampp\htdocs\lib\classes\Swift\Transport\SendmailTransport.php(61): Swift_Transport_AbstractSmtpTransport->start() #3 C:\xampp\htdocs\lib\classes\Swift\Mailer.php(74): Swift_Transport_SendmailTransport->start() #4 C:\xampp\htdocs\Mail.php(20): Swift_Mailer->send(Object(Swift_Message)) #5 {main} thrown in C:\xampp\htdocs\lib\classes\Swift\Transport\StreamBuffer.php on line 268
所以我尝试了一个基本的 mail() 脚本,但它不起作用。我用过stunnel,但似乎不起作用。我完全迷路了。一些指导,教程,任何你能提供的东西,拜托大家了!
Having big problems trying to get my php script to send email. Using this script on my mac:
<?php
require_once 'lib/swift_required.php';
$image = file_get_contents("php://input");
$attachment = Swift_Attachment::newInstance($image, 'submission.jpg', 'image/jpg');
$message = Swift_Message::newInstance()
/*Give the message a subject*/
->setSubject('Your subject')
/*Set the from address with an associative array*/
->setFrom(array('email'=>'Name'))
/*Set the to addresses with an associative array*/
->setTo(array('email'))
/*Give it a body*/
->setBody('Email');
$message->attach($attachment);//<--When the attachment above is commented out, so is this
$transport = Swift_SendmailTransport::newInstance();
$mailer = Swift_Mailer::newInstance($transport);
$mailer->send($message);
?>
email sends fine, attaches the image and is great. However this doesn't work on windows. I've read windows doesnt have a mail server so have spent that last few days fighting with hmailserver, mercury, mailsender etc. trying to get an email to send.
I get a weird error from swiftmailer:
Fatal error: Uncaught exception 'Swift_TransportException' with message 'Process could not be started [The system cannot find the path specified. ]' in C:\xampp\htdocs\lib\classes\Swift\Transport\StreamBuffer.php:268 Stack trace: #0 C:\xampp\htdocs\lib\classes\Swift\Transport\StreamBuffer.php(66): Swift_Transport_StreamBuffer->_establishProcessConnection() #1 C:\xampp\htdocs\lib\classes\Swift\Transport\AbstractSmtpTransport.php(101): Swift_Transport_StreamBuffer->initialize(Array) #2 C:\xampp\htdocs\lib\classes\Swift\Transport\SendmailTransport.php(61): Swift_Transport_AbstractSmtpTransport->start() #3 C:\xampp\htdocs\lib\classes\Swift\Mailer.php(74): Swift_Transport_SendmailTransport->start() #4 C:\xampp\htdocs\Mail.php(20): Swift_Mailer->send(Object(Swift_Message)) #5 {main} thrown in C:\xampp\htdocs\lib\classes\Swift\Transport\StreamBuffer.php on line 268
So I tried a basic mail() script and that doesnt work. I've used stunnel and that doesnt seem to work. I'm completely lost. Some direction, a tutorial, anything you can offer please guys!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Linux 系统上,邮件是通过使用 Sendmail 的 mail() 函数从 PHP 发送的。每当我在 Windows 上使用 Swiftmailer 时,我都会使用 gmail 允许的 SMTP。
http://www.swiftmailer.org/wikidocs/v3/smtpauth
On Linux systems, mail is sent from PHP via the mail() function which uses Sendmail. Whenever I use Swiftmailer on windows, I use SMTP, which gmail allows.
http://www.swiftmailer.org/wikidocs/v3/smtpauth