【发布时间】:2016-11-09 23:30:01
【问题描述】:
<html>
<form method="post" action="email.php">
Email: <input name="email name" id="email" type="text" /><br/>
Message:<br/><text area name="message" id="message" rows="15" cols="40</text area><br>
<input type="submit" value="Submit" />
</form>
<html/>
我有这些代码,我想通过联系表格向 myemail@gmail.com 发送电子邮件,但它说输入至少一个收件人,并且当我输入电子邮件到 $mail-> 如果我更改时添加地址($email)到 $mail->addadress(someone@gmail.com) 即使表单上的电子邮件与默认电子邮件不同,它也会发送到某人@gmail.com,请帮助我。
<?php
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
require("PHPMailerAutoload.php");
require "class.phpmailer.php";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPSecure = "tls";
$mail->Port = 587;
$mail->Host = "smtp.gmail.com";
$mail->Username = "myemail@gmail.com"; // SMTP username
$mail->Password = "*************"; // SMTP password
$mail->AddAddress=$email;
$mail->IsHTML(true);
$mail->Subject = "You have received feedback from your website!";
$mail->Body = $message;
$mail->AltBody = $message;
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>
【问题讨论】:
-
addAddress是 PHPMailer 类中的一个函数,因此您需要将所需的电子邮件作为参数传递。