【发布时间】:2020-09-22 19:39:00
【问题描述】:
我想让我的网站用户能够发送电子邮件。 我使用 PHP,我的主机是 GoDaddy。我认为 PHPMailer 是最好的选择。 我认为我的问题是尝试连接到 GoDaddy 的 PHPMailer。 我应该使用另一个 PHPMailer 吗?
我的代码基于您网站上应该可以工作的示例。 看来这些行: require_once "PHPMailerAutoload.php"; $mail = 新的 PHPMailer; //PHPMailer 对象 防止后续代码工作。 请帮忙。
<?php
if(isset($_POST['send'])){
echo "Sending";
require_once "PHPMailerAutoload.php";
$mail = new PHPMailer; //PHPMailer Object
$mail->setFrom('sender@example.com', 'Rob');
// $mail->addAddress("my godaddy webmail"); //Recipient name is optional
echo "still Sending";
$mail->addAddress("recipient@example.com"); //Recipient name is optional
//Send HTML or Plain Text email
$mail->isHTML(true);
$mail->Subject = "Email Test";
$mail->Body = "<i>This is a text</i>";
$mail->AltBody = "This is the plain text version of the email content";
if(!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent successfully";
}
}`enter code here`
?>
<form method="post">
<input type="submit" name="send" value="Send">
</form>
【问题讨论】:
-
哦,欢迎来到 StackOverflow! :) 我猜你不熟悉composer。如果您现在不想学习所有这些,PHP Mailer 似乎有在没有 composer 的情况下安装的说明,您只需将几个文件复制到您的服务器上并直接
require(...)它们。