使用 phpmailer 使用邮件地址的帖子数据发送电子邮件

发布于 2024-12-09 17:43:24 字数 1172 浏览 1 评论 0原文

我正在尝试根据 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 = "[email protected]";
$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";


}
?>

im trying to email something to a user based on the email address that is entered on the html form. i am using post as the method and i cant figure out how to use that data for the email address using 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 = "[email protected]";
$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";


}
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

错爱 2024-12-16 17:43:24

表单编辑:(

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

删除双引号)

php 编辑:

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

应该可以完成这项工作。

form edit:

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

(removed the double quote)

php edit:

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

should do the job.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文