我已在我网站的主页上创建此表单 -
<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的新手,我也理解我没有定义主题或未能从网站的主页上捕获电子邮件地址。
注意:我收到了电子邮件,但它们包含了这个 - &#34;这是Bold中的邮件正文&#34;而且我没有收到我在联系表格中添加的电子邮件ID。
此外,我不确定在此添加什么 - $ mail-&gt; AddAddress(&#39; info@example.com');
所以我除了reply@example.com之外还创建了另一封电子邮件。
让我知道我在这里做错了什么。
答案 0 :(得分:1)
您需要将捕获变量分配给$mail
对象。
$mail->From = $email;
$mail->FromName = $name;
$mail->Body = $message;
$mail->Subject = $subject;