无法让 xammp 通过 PHP 发送电子邮件

发布于 2024-11-12 04:01:52 字数 2026 浏览 1 评论 0原文

尝试让我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

§普罗旺斯的薰衣草 2024-11-19 04:01:52

在 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文