$mail->addAddress() parameters

5

S.O.S我正在尝试向所选的电子邮件地址(由表单发布)发送消息,因此表单将传递student_id到php脚本,该脚本获取相应的student_email地址(由student_id引用)... 非常感谢您的帮助。 这是我每次收到的错误消息:

无效刷新:您必须提供至少一个收件人电子邮件地址。未发送任何消息 PHP Mailer错误:您必须提供至少一个收件人电子邮件地址。

代码:

<?php require_once("connection.php"); ?>
<?php require_once("functions.php"); ?>
<?php require("class.phpmailer.php");?>


<?php
 // START FORM PROCESSING
 if( isset($_POST['submit'])) { // Form has been submitted.
$student = trim(mysql_prep($_POST['student']));
$re_mail =$student["email"];
$mail = new PHPMailer();
$mail->PluginDir = './';
$mail->IsSMTP();
$mail->Port = 465;
$mail->Host = "smtp.gmail.com"; 
$mail->IsHTML(true); 
$mail->Mailer = "smtp";
$mail->SMTPSecure = "ssl";

$mail->SMTPAuth = true;
$mail->Username = "xxxxx@gmail.com";
$mail->Password = "xxxxxxxxxx";

$mail->SingleTo = true; // if you want to send mail to the users individually so that no recipients can see that who has got the same email.

$mail->From = "xxxxxx@gmail.com";
$mail->FromName = "xxxxxxxxx";

$mail->addAddress($re_mail );

$mail->Subject = "Testing PHP Mailer with localhost ";
$mail->Body = "Hi,This system is working perfectly.";

if(!$mail->Send())
echo "Message was not sent PHP Mailer Error: " . $mail->ErrorInfo;
else
echo "Message has been sent";}
?>



<html>
<body>
<form id="form1" name="form1" method="post" action="">
  <span id="spryselect1">
  <label>Email:
  <select name="student" id="student" tabindex="1">
<?php 
  $students = get_all_students();//this function works fine
  while ($student = mysql_fetch_array($students)) {
  echo "<option value=\"{$student["id"]}\"> {$student["first_name"]}</option> ";
 }
 ?>  
  </select>
  </label>
    <p>
    <label>
    <input type="submit" name="submit" id="submit" value="Submit" />
    </label>
  </p>
</form>

</body>
</html>

注意:我在我的function.php文件中有以下这个函数

function get_all_students() {
        global $connection;
        $query = "SELECT * 
                FROM student ORDER BY first_name ASC";
        $student_set = mysql_query($query, $connection);
        confirm_query($student_set);
        return $student_set;
    }

请提供一些无效的电子邮件地址示例。 - Pekka
mysql_* 函数已经正式弃用,你应该迁移到 MySQLi 或 PDO :) - Terry
1个回答

2

最终我得到了答案,感谢所有在这里提供帮助的人 :)

<?php require_once("connection.php"); ?>
<?php require_once("functions.php"); ?>
<?php require("class.phpmailer.php");?>
<?php
// START FORM PROCESSING
if( isset($_POST['submit'])) { // Form has been submitted.

$student = trim(mysql_prep($_POST['student']));
$re_to_student=get_student_by_id($_POST['proposer']);

//this is another function i have in my function.php

$st_email = $re_to_student["email"];


$mail = new PHPMailer();
$mail->PluginDir = './';
$mail->IsSMTP();
$mail->Port = 465;
$mail->Host = "smtp.gmail.com"; 
$mail->IsHTML(true); 
$mail->Mailer = "smtp";
$mail->SMTPSecure = "ssl";

$mail->SMTPAuth = true;
$mail->Username = "mymail@gmail.com";
$mail->Password = "mypassword";

$mail->SingleTo = true; // if you want to send mail to the users individually so that no recipients can see that who has got the same email.

$mail->From = "mymail@gmail.com";
$mail->FromName = "myweb.com";

$mail->addAddress($st_email);

$mail->Subject = "test";
$mail->Body = "Hi,This system is working perfectly.";

if(!$mail->Send())
echo "Message was not sent PHP Mailer Error: " . $mail->ErrorInfo;
else
echo "Message has been sent";}


?>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接