gpt4 book ai didi

phpmailer - $mail->addAddress() 参数

转载 作者:行者123 更新时间:2023-12-04 21:25:16 26 4
gpt4 key购买 nike

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

Invalid refreshed: You must provide at least one recipient email address. Message was not sent PHP Mailer Error: You must provide at least one recipient email address.



编码:
<?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;
}

最佳答案

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

<?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";}


?>

关于phpmailer - $mail->addAddress() 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4521153/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com