简体   繁体   English

在 php 中发送电子邮件 - swiftmailer

[英]Sending an email in php - swiftmailer

I've been searching for days if not weeks on how to automatically send a simple e-mail in php after a user completes my form.在用户完成我的表单后,我一直在寻找如何在 php 中自动发送简单电子邮件的问题。 I've tried Pear, PHP mail, Swiftmailer, changed my php.ini, tried different servers and I'm going mad from none of it working.我尝试过 Pear、PHP 邮件、Swiftmailer,更改了我的 php.ini,尝试了不同的服务器,但我都快要疯了。 I have not successfully sent one e-mail yet.我还没有成功发送一封电子邮件。 I've searched endlessly but I still have no idea what to do and why nothing is working.我无休止地搜索,但我仍然不知道该怎么做以及为什么没有任何效果。 At the moment I'm using Swiftmailer (second time round).目前我正在使用 Swiftmailer(第二次)。 I set up a test page with code:我用代码设置了一个测试页面:

<?php
require_once 'swift/lib/swift_required.php';


// CREATE TRANSPORT CONFIG
$transport = Swift_MailTransport::newInstance();


// CREATE MSG
$message = Swift_Message::newInstance();

// SET PRIORITY TO HIGH
$message->setPriority(2);

// SUBJECT
$message->setSubject('Subject');

// FROM
$message->setFrom(array('example@btopenworld.com'));

// TO
$message->setTo(array('example@googlemail.com'));

// EMAIL BODY
$message->setBody('Test');

// SEND
$mailer = Swift_Mailer::newInstance($transport);
$mailer->send($message);

if (!$mailer->send($message, $failures)) {
echo "Failures:";
print_r($failures);
}


?>

Looking at a similar post someone suggested the last part of the code to see errors and my error is:查看类似的帖子,有人建议在代码的最后一部分查看错误,我的错误是:

Failures:Array ( [0] => example@googlemail.com )

No matter what e-mail I change it to (all using e-mails I have, so real e-mails) it doesn't work.无论我将其更改为什么电子邮件(全部使用我拥有的电子邮件,因此是真实的电子邮件),它都不起作用。 If anyone has any help or suggestions it would be hugely appreciated.如果有人有任何帮助或建议,将不胜感激。

example@btopenworld.com

Unless you are using a btopenworld server to send the E-Mail from, this is not going to work.除非您使用 btopenworld 服务器来发送电子邮件,否则这是行不通的。 The E-Mails from address needs to be associated with the server you are sending the message from.这些电子邮件from地址需要与您从发送邮件的服务器相关联。 You can put the BT address into the reply-to header.您可以将 BT 地址放入reply-to标头中。

Also, SwiftMailer should have a "debug" switch telling you exactly what goes wrong, but I can't find it in the docs right now.此外,SwiftMailer 应该有一个“调试”开关,告诉您究竟出了什么问题,但我现在在文档中找不到它。 Here is a logger plugin for Swiftmailer that should help if all else fails.是 Swiftmailer 的记录器插件,如果其他方法都失败了,它应该会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM