From $list i am getting all the emails that are posted by form after using explode
$list = explode(',', $guest_email);
foreach ($list as $k => $v) {
$mail = new PHPmailer();
$mail->From = $smtp_user;
$mail->FromName = $fromname;
$mail->Mailer = "mail";
$mail->Subject = "";
$mail->IsHTML(true);
//$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = ;
$mail->SMTPSecure = '';
$mail->Host = $smtp;
$mail->Port = $port;
$mail->Password = $sm;
$mail->Username = $sm;
$mail->Body = $bodyContent;
in below line the mail are going to all posted email address, in next line i want to add all the emails in cc, but it is not working
$mail->AddAddress($v);
$mail->Addcc($v)
$mail->AddReplyTo($smtp_user);
if(!$mail->Send()){
echo "Mailer Error: " . $mail->ErrorInfo;
}else{
echo "SUCCESS";
}
}
how to send all email in $mail->Addcc($v)
Related
I have a script that I'm running using phpmailer - it's supposed to send 2 emails - a verification email and a request email. for some reason it's sending the verification email twice. I've gone over the code 100 times and I can't figure out why. Relevant code is below - it's not nested in any loop or condition. the "code" is a get variable and "auth" is pulled from a database.
<?php
if ($code==$auth) {
$mailtitle="message 1";
$message="message text";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "mail.mysite.org";
$mail->From = "authorize#mysite.org";
$mail->FromName = "mysite";
$mail->AddAddress($dre);
$mail->SMTPAuth = "true";
$mail->SMTPSecure = 'tls';
$mail->Username = "authorize#mysite.org";
$mail->Password = "thepassword";
$mail->Port = "587";
$mail->Subject = $mailtitle;
$mail->Body = $message;
$mail->isHTML(true);
$mail->WordWrap = 180;
$mail->send();
$mailtitle="message 2 title";
$message="message text";
$mail1 = new PHPMailer();
$mail1->IsSMTP();
$mail1->Host = "mail.mysite.org";
$mail1->From = "authorize#mysite.org";
$mail1->FromName = "mysite";
$mail1->AddAddress('authorize#mysite.org');
foreach ($pea as $px) {
$mail1->addBCC($px);
}
foreach ($sea as $sx) {
$mail1->addBCC($sx);
}
$mail1->SMTPAuth = "true";
$mail1->SMTPSecure = 'tls';
$mail1->Username = "authorize#mysite.org";
$mail1->Password = "thepassword";
$mail1->Port = "587";
$mail1->Subject = $mailtitle;
$mail1->Body = $message;
$mail1->isHTML(true);
$mail1->WordWrap = 180;
$mail1->send();
}
?>```
You may disable the BCC by REMOVING the following
foreach ($pea as $px) {
$mail1->addBCC($px);
}
foreach ($sea as $sx) {
$mail1->addBCC($sx);
}
I'm frustrated to fix this.
One time I made it work. The next day, an error annoys me:
Warning: Attempt to assign property of non-object in C:\XAMPP\htdocs\HAF\includes\sendmail.php on line 356
Help me fix this :(
Here's my code:
sendmail.php
class SendMail {
function notification($recipient, $name, $subject, $message) {
global $email;
$email->Host = "smtp.gmail.com";
$email->SMTPAuth = true;
$email->Username = "******#gmail.com";
$email->Password = "**********";
$email->SMTPSecure = "tls";
$email->Port = 465;
$email->setFrom('admin#gmail.com', 'My WebApp');
$email->addAddress($recipient);
$email->isHTML(true);
$email->Subject = $subject;
$email->Body = $message;
if(!$email->send()) {
return false;
} else {
return true;
}
}
}
index.php
$email = "jaydenjames#gmail.com";
$name = "Jayden James";
$message = "Welcome {$name}!";
$SendMail->notification($email, $name, 'Welcome guest!', $message);
update answer with gmail configuration....
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet="UTF-8";
$mail->SMTPSecure = 'tls';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->Username = 'MyUsername#gmail.com';
$mail->Password = 'valid password';
$mail->SMTPAuth = true;
$mail->From = 'MyUsername#gmail.com';
$mail->FromName = 'Mohammad Masoudian';
$mail->AddAddress('anotherValidGmail#gmail.com');
$mail->AddReplyTo('phoenixd110#gmail.com', 'Information');
$mail->IsHTML(true);
$mail->Subject = "PHPMailer Test Subject via Sendmail, basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->Body = "Hello";
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message sent!";
}
I want to create a loop for my mail system that uses the format
stan.smith#americandadcia.fx, Stan Smith
So that I can pass it through my function
function SendEmail($to,$fromName, $subject, $message)
{
date_default_timezone_set('Etc/UTC');
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = smtp_host;
$mail->Port = smtp_port;
$mail->SMTPSecure = smtp_protocol;
$mail->SMTPAuth = true;
$mail->Username = smtp_user;
$mail->Password = smtp_pass;
$mail->setFrom(smtp_user, $fromName);
$mail->addReplyTo(smtp_user, $fromName);
$mail->addAddress($to);
$mail->Subject = $subject;
$mail->msgHTML($message);
$mail->send();
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
}
}
This code is to go through a loop, so say you have
Stan Smith, Roger Smith and Francine Smith the form input would have
stan.smith#americandad.fx, Stan Smith; roger.smith#amongyou.ufo, Roger Smith; francine.smith#desperatehousewives.fox, Francine Smith
The addresses would then be passed into my functions file and ran through the function to send the email
$mail = new MailSystem();
$emails=$_POST['emailTo'];
$email=explode(";",$emails);
foreach($email as $address) {
echo $mail->SendEmail($address, SITE_NAME." Newsletter", $_POST['emailSubject'], $_POST['emailBody']);
}
My Problem is that when the email attempts to send it's going to try to run $mail->addAddress($address) and I get the response that it's an invalid address. I can go in and manually set the addAddress with my email", "My name" but when it goes through this way it resolves to invalid address.
On the addAddress() you have to split the receiver name and address. Your function should look like the following:
function SendEmail($to,$fromName, $subject, $message)
{
date_default_timezone_set('Etc/UTC');
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = smtp_host;
$mail->Port = smtp_port;
$mail->SMTPSecure = smtp_protocol;
$mail->SMTPAuth = true;
$mail->Username = smtp_user;
$mail->Password = smtp_pass;
$mail->setFrom(smtp_user, $fromName);
$mail->addReplyTo(smtp_user, $fromName);
//split the to on , to get mail address and receiver name.
$address = explode(',', $to);
//check if the name is available.
if (!isset($address[1])) {
$mail->addAddress($address[0]);
} else {
$mail->addAddress($address[0], $address[1]);
}
$mail->Subject = $subject;
$mail->msgHTML($message);
//remove the following line because duplicate sending!!!
//$mail->send();
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
}
}
I have some troubles with my sending loop with PHP Mailer:
<?php
foreach ($packTabCible as $key => $pack) {
// PHPMailer
$mail = new PHPMailer;
$mail->Mailer = "smtp";
$mail->isSMTP();
$mail->SMTPKeepAlive = true;
$mail->SMTPAuth = true;
$mail->Encoding = '8bit';
$mail->SMTPDebug = 3;
$mail->setLanguage('fr', './PHPMailer/language/');
$mail->CharSet = 'UTF-8';
$mail->WordWrap = 10000;
$mail->Host = $hostname;
$mail->Username = $username;
$mail->Password = $pass;
$mail->SMTPSecure = $tls;
$mail->Port = $port;
$mail->FromName = utf8_decode($from_name);
$mail->isHTML(true);
$mail->Subject = utf8_decode($sujet);
$mail->From = $from_mail;
foreach ($pack as $email => $md5) {
$mail->addAddress($email);
$header = str_replace("#miroir#", $link_miroir, $ip_header_html);
$footer = str_replace("#lien#", $link_unsub, $ip_footer_html);
$content = str_replace("<body>", "<body>".$header, $message);
$content = str_replace("</body>", $footer.'</body>', $content);
$content = str_replace("#email#", $email, $content);
$mail->Body = $content;
$mail->AltBody = str_replace("#miroir#", $link_miroir, utf8_decode($ip_header_txt))
. $txt
. str_replace("#lien#", $link_unsub, $ip_footer_txt);
$mail->send();
$mail->clearAddresses();
usleep($timer);
}
$mail->SmtpClose();
usleep(5000000);
}
?>
I'm 100% sure of the validity of the parameters I send to PHPMailer.
There is 2 loops, and I reset the connexion after each loop of $packTabCible with $mail->SmtpClose();
But, PHPMailer return the error:
The following From address failed: news#my-domain.com : MAIL FROM command failed,0 ok
,
2,SMTP server error: MAIL FROM command failed Detail: 0 ok
SMTP code:
2SMTP server error: MAIL FROM command failed Detail: 0 ok
SMTP code:
2
But news#my-domain.com is the good one so the problem is elsewhere...
If someone have an idea, big thanks
I have used PHPMailer for SMTP and there is problem in sending mail with error "Mailer Error: The following From address failed: no-reply#mydomain.org.uk"
My code is as follows:
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = "localhost;"; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = ""; // SMTP username
$mail->Password = ""; // SMTP password
$mail->From = $email_address;
$mail->FromName = $email_address;
$mail->AddAddress($arrStudent[0]["email"]);
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "Subject";
$theData = str_replace("\n", "<BR>", $stuff);
$mail->Body = $theData; // "This is the <b>HTML body</b>";
$mail->AltBody = $stuff;
if (!$mail->Send()) {
$sent = 0;
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
i researched everything and when i debug inside class.smtp.php i found error the function "get_lines()" is returning error value "550 Authentication failed"
The code was working fine previously, i am wondering how this problem came suddenly.
Desperate for some help.
Thanks,
Biplab
public function sendEmail ( $subject, $to, $body, $from = FALSE ) {
require_once('mailer.class.php');
$mailer = new PHPMailer();
//do we use SMTP?
if ( USE_SMTP ) {
$mailer->IsSMTP();
$mailer->SMTPAuth = true;
$mailer->Host = SMTP_HOST;
$mailer->Port = SMTP_PORT;
$mailer->Password = '';
$mailer->Username = '';
if(USE_SSL)
$mailer->SMTPSecure = "ssl";
}
$mailer->SetFrom($from?$from:ADMIN_EMAIL, ADMIN_NAME);
$mailer->AddReplyTo ( ADMIN_EMAIL, ADMIN_NAME );
$mailer->AddAddress($to);
$mailer->Subject = $subject;
//$mailer->WordWrap = 100;
$mailer->IsHTML ( TRUE );
$mailer->MsgHTML($body);
require_once('util.class.php');
$mailer->AltBody = Util::html2text ( $body );
//$mail->AddAttachment("images/phpmailer.gif"); // attachment
//$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if ( ! $mailer->Send() ) {
return FALSE;
}
else {
$mailer->ClearAllRecipients ();
$mailer->ClearReplyTos ();
return TRUE;
}
}
I've used like that... SetFrom should be used in place of From... that's your error buddy... :))
try adding belowe line to php.ini
extension=php_openssl.dll
restart and try again
I am using YII's Mailer with PHPMailer, and this works for me:
$mail = Yii::createComponent('application.extensions.mailer.EMailer');
$mail->Username = $this->SMTP_USERNAME; // SMTP username
$mail->Password = $this->SMTP_PASSWORD; // SMTP password
$mail->SMTPAuth = true;
$mail->From = $this->fromAddress;
$mail->Host = $this->SMTP_SERVER_ADDRESS;
$mail->FromName = $this->fromName;
$mail->CharSet = 'UTF-8';
$mail->Subject = Yii::t('mailer', $this->subject);
$mail->Body = $this->message;
$mail->AddReplyTo($this->toAddress);
$mail->AddAddress($this->toAddress);
$mail->IsSMTP(true);
$mail->IsHTML(true);
$mail->Send();
Hope that helps?