Параметры $ mail-> addAddress () - PullRequest
       6

Параметры $ mail-> addAddress ()

5 голосов
/ 23 декабря 2010

SOS Я пытаюсь отправить сообщение на выбранный адрес электронной почты (отправленный с помощью формы), чтобы форма передавала student_id в сценарий php, который получает соответствующий адрес student_email (на который ссылается student_id),,, Я высоко ценю вашу помощь.это сообщение об ошибке, которое я получаю каждый раз ,,

Неправильно обновлено: необходимо указать хотя бы один адрес электронной почты получателя.Сообщение не было отправлено. PHP Mailer Error: Вы должны указать хотя бы один адрес электронной почты получателя.

код:

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

1 Ответ

2 голосов
/ 24 декабря 2010

Наконец-то я получил ответ ,, спасибо всем, кто предложил помощь здесь:)

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


?>
...