使用phpmailer通过邮件数据发送电子邮件地址

时间:2011-10-15 08:47:09

标签: php html forms phpmailer

我试图根据在html表单上输入的电子邮件地址向用户发送电子邮件。我使用post作为方法,我无法弄清楚如何使用phpmailer将该数据用于电子邮件地址。

<!DOCTYPE html>
<html>
<form method='post'>
<input type='email' value='@domain.com' name='emailaddress'>
<input type='submit' value='submit' name='submit'> 
</form>
</html>
<?php
if (isset($_REQUEST['Submit'])) {
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail-> IsSMTP();
$mail->Host = "mail.domain.com";

$mail->Username = 'username';
$mail->Password = 'password';
$mail->From = "foo@bar.com";
$mail->FromName = "foo bar";
$mail->AddAddress = (HERE IS WHERE I WANT TO ENTER emailaddress FROM THE FORM);
$mail->Subject = "test1";
$mail->Body = "Test 1 of PHPMailer.";
$mail->IsHTML(true);
$mail->Port = 25;
$mail->AddAttachment('sample.pdf','sample.pdf');
//$mail->SMTPSecure = 'ssl';
if(!$mail->Send())
{
echo "Message did not sent <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}

echo "Message has been sent";


}
?>

1 个答案:

答案 0 :(得分:3)

表单编辑:

<input type='email' value='@domain.com' name='emailaddress'>

(删除双引号)

php编辑:

$mail ->AddAddress = $_POST['emailaddress'];

应该做的。