【问题标题】:Getting Blank Emails with PHPmailer使用 PHPmailer 获取空白电子邮件
【发布时间】:2016-03-26 17:04:28
【问题描述】:

我已经在我的网站主页上创建了这个表单 -

<form action="mail.php" method="post">
<p>Name:</p> <input type="text" name="name" size="40">
<p>Email:</p> <input type="email" name="email" size="40">
<p>Subject:</p> <input type="text" name="subject" size="40">
<p>Message: </p><textarea name="message" rows="6" cols="41"></textarea>
<p><input type="submit" value="Contact Us"></p>
</form>

现在我在 mail.php 文件中粘贴了以下代码注意我也在使用 phpmailer ..

<?php
require '/home/hostiojv/public_html/verticaldesign.net/FinalComeagain/phpmailer/class.phpmailer.php';

$name = $_POST["name"];
$email = $_POST["email"];
$subject = $_POST["subject"];
$message = $_POST["message"];

$mail = new PHPMailer;

$mail->IsSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'p3XXXX.prod.phx3.secureXXXX.net';  // Specify main and backup server
$mail->Port = 465;
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'reply@example.com';                            // SMTP username
$mail->Password = 'XXXX';                           // SMTP password
$mail->SMTPSecure = 'ssl';                            // Enable encryption, 'ssl' also accepted
$mail->SMTPDebug = 1;


$mail->From = 'reply@example.com';
$mail->FromName = 'John Smith';
$mail->AddAddress('info@example.com');               // Name is optional

$mail->WordWrap = 50;                                 // Set word wrap to 50 characters
$mail->IsHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->Send()) {
   echo 'Message could not be sent.';
   echo 'Mailer Error: ' . $mail->ErrorInfo;
   exit;
}

echo 'Message has been sent';
header("Location: http://verticaldesign.net/FinalComeagain/index.html");
?>

我是 PHP 新手,而且我了解我没有定义主题或未能从网站主页捕获电子邮件地址的事实。

注意:我收到了电子邮件,但它们包含以下内容 - “这是粗体的消息正文”,而且我没有收到我在联系表格中添加的电子邮件 ID。

我也不确定在这里添加什么 - $mail->AddAddress('info@example.com');
所以除了reply@example.com 之外,我还创建了另一封电子邮件..

让我知道我在这里做错了什么。

【问题讨论】:

    标签: php email


    【解决方案1】:

    您需要将捕获变量分配给您的$mail 对象。

    $mail->From = $email;
    $mail->FromName = $name;
    $mail->Body    = $message;
    $mail->Subject = $subject;
    

    【讨论】:

    • 我不知道该怎么说谢谢你:D你刚刚拯救了我的一天
    • @danishdeb 不用担心,很高兴为您提供帮助。
    猜你喜欢
    • 2013-11-04
    • 2015-09-08
    • 2015-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多