【问题标题】:how to send on contact form using phpmailer如何使用 phpmailer 在联系表上发送
【发布时间】: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 类中的一个函数,因此您需要将所需的电子邮件作为参数传递。

标签: php email


【解决方案1】:

AddAddress 是一种方法,而不是属性。

$mail->AddAddress=$email;

应该是:

$mail->AddAddress($email);

【讨论】:

  • 感谢您的评论,但仍至少添加一个收据
  • 请参阅github.com/PHPMailer/PHPMailer/issues/441。检查var_dump(PHPMailer::validateAddress($email)); 的输出以排除错误。哪个版本的 PHP?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-02-24
  • 2021-06-19
  • 2017-06-13
  • 2019-10-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多