Unable to send email to multiple user - phpmailer

Right now I am doing a system. This system will send notification if educators have update a quiz. I want to send email to multiple user. I have refer this question 17860172 and Its solution but Its not works.
This is my code:
$result = mysql_query("SELECT * FROM student WHERE className='$classname'");
while ($rec= mysql_fetch_array($result))
{
$title = "Quiz Information";
$body = "Your quiz have been updated";
$email = $rec['stuEmail'];
}
include_once("mailer/mailer.php");
okey, for the mailer.php :
require_once("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Mailer = "smtp";
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = "***";
$mail->Password = "***";
$mail->From = "iii#gmail.com";
$mail->FromName = "i System";
$mail->AddAddress($email);
$mail->Subject = $title;
$mail->MsgHTML($body);
if (file_exists($path)){
$mail->AddAttachment($path);
}
$mail->WordWrap = 50;
$mail->Send();
I want to send to all email in database based on className but when I click submit button the email doesn't send at all.

You can try this :
$result = mysql_query("SELECT * FROM student WHERE className='$classname'");
while ($rec= mysql_fetch_array($result))
{
$title = "Quiz Information";
$body = "Your quiz have been updated";
$email = $rec['stuEmail'];
mail = new PHPMailer();
$mail->IsSMTP();
$mail->Mailer = "smtp";
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = "***";
$mail->Password = "***";
$mail->From = "iii#gmail.com";
$mail->FromName = "i System";
$mail->AddAddress($email);
$mail->Subject = $title;
$mail->MsgHTML($body);
if (file_exists($path)){
$mail->AddAttachment($path);
}
$mail->WordWrap = 50;
$mail->Send();
}

Related

phpmailer : blank subject if subject contents accent

When I send an email whose subject contains accents in subject, email arrives with blank subject:
$mail = new PHPMailer(true);
$mail->CharSet = "UTF-8";
$mail->IsSMTP();
$mail->Host = SMTPHost;
$mail->SMTPDebug = SMTPDebug;
$mail->SMTPAuth = SMTPAuth;
$mail->Port = SMTPPort;
$mail->Username = SMTPUsername;
$mail->Password = SMTPPassword;
$mail->SMTPSecure = "ssl";
$mail->IsHTML(true);
$mail->AddAddress($to, $to);
$mail->SetFrom($from, $from);
$mail->AddReplyTo($from, $from);
$subject = "oubliƩ ?"; // if "oublie": it works fine !
$mail->Subject = $subject;
$mail->Send();

Email not send in function codeigniter php mailer

this controller code.
i found problem that "Failed to send password, please try again!" .
What should I do?
$mail_message='Dear '.$row[0]['name'].','. "\r\n";
$mail_message.='Your <b>Password</b> is <b>'.$passwordplain.'</b>'."\r\n";
$mail_message.='<br>Please Update your password.';
$mail_message.='<br>Thanks & Regards';
$mail_message.='<br>IT Ardiles';
$mail = new PHPMailer;
$mail->IsSendmail();
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = '';
$mail->Port = 587;
$mail->Host = "mail.xxxxx.co.id";
$subject = 'Forgot Password';
$mail->AddAddress(xxx#xxxxx.co.id);
$mail->IsMail();
$mail->From = 'it#xxxxx.co.id';
$mail->Password = 'xxxxx';
$mail->FromName = 'IT';
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body = $mail_message;
$mail->Send();

how to send email to multiple users in php mailer

I want to send email to two users when the count is not zero. When I am making
$semail = $row_seller['seller_email']; its working but when I make it
$semail = $row_seller['seller_email'].",example#gmail.com"; its not, I want to send it to both. How can i do it.
<?php
$query1 = "select * from `seller` where seller_pincode = $pincode";
$run_query1 = mysqli_query($con, $query1);
$count_seller = mysqli_num_rows($run_query1);
if ($count_seller == 0)
{
$semail = "example#gmail.com";
$sname = $saddress = $spincode = $scity = $sstate = $sphone = $sgst = $span = "Not Available";
}
else
{
while ($row_seller = mysqli_fetch_array($run_query1))
{
$semail = $row_seller['seller_email'] . ",example#gmail.com";
}
}
$email = $semail;
$subject = "Order Details";
$message = 'You got a new Order!!! ";
require_once('mailer / class . phpmailer . php);
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Subject = $subject;
$mail->MsgHTML($message);
$mail->Send();
You need to use addAddress method or addCC for add copy, like so
$mail->addAddress('mail#domain.com', 'NAME'); //add address
$mail->addCC('mail#domain.com', 'NAME'); / add copy
Github

The following From address failed: webdeveloper.hadi#gmail.com : Called Mail() without being connected

Guys I Got his error it is working # localhost but does't work on my host
http://myownprojects.co.nf/ ??
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = 'smtp.gmail.com';
$mail->SMTPSecure = "ssl";
$mail->Port = 465;
$mail->IsHTML(true);
$mail->Username = "webdeveloper.hadi#gmail.com";
$mail->Password = '**********';
$mail->setFrom("webdeveloper.hadi#gmail.com");
$mail->Subject= "Your confirmation Mail";
$mail->AddEmbeddedImage('images/me.jpg', 'meimg', 'images/me.jpg');
$mail->Body = "Please click on the link";
$mail->addAddress(webdeveloper.hadi#gmail.com);
if($mail->Send()){
}else{
}
Try the following:
$mail->SMTPSecure = "tls";
$mail->Port = 587;

SMTP ERROR: Failed to connect to server: With PHPMAILER in Dreamhost

I can not send mail using the PHPMailer lib. My site is hosted on dreamhost,
with SMTP gmail I can send more properly to the configuration provided by the hosting the only return is:
SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: Name or service not known (0)
SMTP connect() failed.
My code:
<?php
date_default_timezone_set('Etc/UTC');
require 'vendor/phpmailer/phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$name = trim(stripslashes($_POST['name']));
$from = trim(stripslashes($_POST['email']));
$subject = trim(stripslashes($_POST['subject']));
$message = trim(stripslashes($_POST['message']));
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = 'mail.example.com.br';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = 'e-mail#example.com';
$mail->Password = 'password';
$mail->SMTPSecure = 'tls';
$mail->Debugoutput = 'html';
$mail->isHTML(true);
$mail->setFrom($from, $name);
$mail->addReplyTo($from, $name);
$mail->addAddress('email#example.com');
$mail->Subject = $subject;
$mail->Body = $message;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
`
I managed to solve the problem, first replaces the e-mail sent to an e-mail sender#example.com own client, then tried some documentation of dreamhost, made the necessary changes, the code:
date_default_timezone_set('Etc/UTC');
require 'vendor/phpmailer/phpmailer/PHPMailerAutoload.php';
$subject = trim(stripslashes($_POST['subject']));
$name = trim(stripslashes($_POST['name']));
$from = trim(stripslashes($_POST['email']));
$body = trim(stripslashes($_POST['message']));
$mail = new PHPMailer;
$mail->isSMTP();
$mail->CharSet = 'UTF-8';
$mail->SMTPDebug = 1;
$mail->Host = 'mail.example.com.br';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = 'sender#example.com.br';
$mail->Password = 'password';
$mail->Debugoutput = 'html';
$mail->isHTML(true);
$mail->setFrom('sender#dexample.com.br', 'DontAnswer');
$mail->addReplyTo($from, $name);
$mail->addAddress('contact#example.com.br');
$mail->Subject = $subject;
$mail->Body = $body;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
In dreamhost documentation says it should be repeated sending e-mail in setFrom () method; after these changes the form worked perfectly.

Resources