require_once( './PHPMailer-master/PHPMailerAutoload.php');
$mail = new PHPMailer();
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.office365.com';
$mail->ClearReplyTos();
$mail->addReplyTo($organizer_email, $organizer);// Specify main and backup server
$mail->SetFrom('xyx#xyx.com', 'zyx');
$mail->SMTPAuth = tls; // Enable SMTP authentication
$mail->Username = 'xyz#xyz.com'; // SMTP username
$mail->Password = 'xyzzzzz'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->Port = 587; //Set the SMTP port number - 587 for authenticated TLS
$mail->addAddress($organizer_email); // Add a recipient
$content = file_get_contents($resume_attach_path);
$content = chunk_split(base64_encode($content));
$eol = "\r\n";
$tags = explode(',', $to);
foreach ($tags as $tag) {
$mail->addCC($tag);
}
$mail->WordWrap = 50;
$mail->Subject = $subject;
$mail->Body = $desc;
$mail->AltBody = $text; // in your case once more the $text string
$mail->Ical = $text; // ical format, in your case $text string
$mail->isHTML(true); // Set email format to HTML
//$mail->addStringAttachment($resume_attach_path,'base64');
if ($mail->send()) {
return true;
}else{
return false;
}
if i use addAttachment i can just see the attachment, cannot see the ical invite ,but if i remove the attachment i can see the ical invite,how can i send both inline ical and external document attachment in phpmailer.
I am showing you a simple working example here
<?php
function sendMail($subject, $body, $name, $email, $attachment = null){
$mail = new PHPMailer(true);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "**************"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "*************"; // GMAIL username
$mail->Password = "***********"; // GMAIL password
//Typical mail data
$mail->AddAddress($email, $name);
$mail->SetFrom('*********', '************');
$mail->Subject = $subject;
$mail->Body = $body;
$mail->IsHTML(true);
if($attachment){
$mail->AddAttachment($attachment['tmp_name'],
$attachment['name']);
}
try{
$mail->Send();
} catch(Exception $e){
//Something went bad
// print_r($e);
echo "Fail :(";
die;
}
}
?>
In this code $attachment is $_FILES['file']. How to call this function is given below.
sendMail($subject, $body, $name, $email, $_FILES['file']);
To use Ical in mailer see a Stackoverflow Question
According to comment in PHPMailer code:
Only supported in simple alt or alt_inline message types
when you add other attachments, part of adding Ical file based on Ical property is ommited.
Related
I don't know how to send a mail using PHPmailer in a function.
I want to do something similar to this - when I'll want to send a mail, I'll just call a function (like send::mail()). here is my code:
<?php
require '.\vendor\autoload.php';
//PHPMailer Object
use PHPMailer\PHPMailer\PHPMailer;
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->IsSendmail();
//From email address and name
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->setFrom('my.bot.mail#gmail.com', 'Bot name');
$mail->Password = "########"; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465;
//To address and name
$mail->addAddress("mymail#gmail.com"); //Recipient name is optional
//Address to which recipient will reply
//Send HTML or Plain Text email
$mail->isHTML(true);
$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";
$mail->Mailer = "sendmail";
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
?>
can someone help me put it into a function? when I tried, the "use" command didn't work.
First, you must determine the data.
$mailHost = '';
$mailSMTPAuth = '';
$mailUsername = '';
$mailPassword = '';
$mailSMTPSecure = '';
$mailPort = '';
$mailSenderAddress = '';
$mailSenderName = '';
Then you can generate a function that contains only the recipient, subject and message, and you can send the mail easily by pull the settings into this function:
function sendMail($sendMailAdress, $sendMailName, $sendMailSubject, $sendMailMessage) {
global $mailHost;
global $mailSMTPAuth;
global $mailUsername;
global $mailPassword;
global $mailSMTPSecure;
global $mailPort;
global $mailSenderAddress;
global $mailSenderName;
require_once('class/phpmailer/PHPMailerAutoload.php');
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = $mailHost; // Specify main and backup SMTP servers
$mail->SMTPAuth = $mailSMTPAuth; // Enable SMTP authentication
$mail->Username = $mailUsername; // SMTP username or mail
$mail->Password = $mailPassword; // SMTP password
$mail->SMTPSecure = $mailSMTPSecure; // Enable TLS encryption, `ssl` also accepted
$mail->Port = $mailPort; // TCP port to connect to
$mail->CharSet = 'utf-8';
$mail->setFrom($mailSenderAddress, $mailSenderName);
$mail->addAddress($sendMailAdress, $sendMailName); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $sendMailSubject;
$mail->Body = $sendMailMessage;
if(!$mail->send()) {
return false;
} else {
return true;
}
}
The function will work like this:
sendMail('hello#test.com', 'Test User', 'Subject of test mail', 'And your mail message);
When I use phpmailer to send four pdf attachments, one is sent as pdf and three of them as plain text. Like this is sent only on macbook app mail. On gamil sent all 4 attachments well.
enter image description here
enter code here
$mail = new PHPMailer(true);
try {
$mail->CharSet = 'UTF-8';
//Server settings
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '***************'; // SMTP username
$mail->Password = '***************'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
//Recipients
$mail->setFrom('ebytyebyty#gmail.com', 'ebyty dokumenty');
// Add a recipient;
$mail->addAddress('drakxy998#gmail.com');
$mail->addAddress($email);
// Attachments
$mail->addAttachment('Objednávka'.$id_fakt.'.pdf', $name = 'Objednávka_'.$id_fakt.'.pdf', $encoding = 'base64', $type = 'application/pdf'); // Add attachments
$mail->addAttachment('Plnomocenstvo.pdf', $name = 'Plnomocenstvo.pdf', $encoding = 'base64', $type = 'application/pdf'); // Optional name
$mail->addAttachment('Súhlassospracúvanímosobnýchúdajov.pdf', $name = 'Súhlas_so_spracúvaním_osobných_údajov.pdf', $encoding = 'base64', $type = 'application/pdf');
$mail->addAttachment('Vyhlásenieomajetku.pdf', $name = 'Vyhlásenie_o_majetku.pdf', $encoding = 'base64', $type = 'application/pdf');
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'ebyty dokumenty';
$mail->Body = 'text';
$mail->AltBody = 'ebyty dokumenty';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}`enter code here`
I am trying to send a fax via the eFax service. As I understand, this should be as easy as sending a simple email to the specific address.
I use PHPMailer for emails. Ordinary emails are sending fine. Even when I send to an efax address $mail->send returns true, that means that the email was sent seccessfully, but the recipient didn't receive the fax.
Any suggestions?
Thank you.
function sendFax($fax, $msg) {
$efax_number = $fax . "#efaxsend.com";
$mail = new PHPMailer;
$mail->CharSet = 'UTF-8';
$mail->SMTPDebug = 3;
$mail->isSMTP();
$mail->Host = EMAIL_HOST; // Set mailer to use SMTP
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = EMAIL_SMTP_USERNAME;
$mail->Password = EMAIL_SMTP_PASSWORD; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;
//From email address and name
$mail->From = "orders#orderapp.com";
$mail->FromName = "Test";
//To address and name
$mail->addAddress($efax_number); // SEND EMAIL TO USER
//Send HTML or Plain Text email
$mail->isHTML(false);
$mail->Subject = ' New Order Fax ';
$mail->Body = $msg;
$mail->AltBody = "Sample";
$result = $mail->send();
if (!$result)
{
...
}
else
{
...
}
}
I am trying to send an email in wordpress. This code works fine If I send email with simple php file but when I am pasting that file in wordpress along with this code, nothing happened. I am sure there is something I am not aware of.
if(isset($_POST['details_submit'])){
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Host = $smtp_server; // Specify main and backup SMTP servers
$mail->Username = $username; // SMTP username
$mail->Password = $password; // SMTP password
$mail->SMTPSecure = "tls"; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom("orders#test.com", "Orders Test");
$mail->addAddress('mark#aol.com', 'Mark'); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$bodyContent = 'testing message';
$mail->Subject = 'Hello Checking' ;
$mail->Body = $bodyContent;
$mail->AltBody = $bodyContent;
if(!$mail->send()) {
echo "Message could not be sent.";
$error = '<div class="alert alert-danger"><strong>Mailer Error: '. $mail->ErrorInfo.'</strong></div>';
} else {
$error = '<div class="alert alert-success"><strong>Message has been sent</strong></div>';
}
}
}
Inconsistent duplicate emails occurring when using php mailer.
Function that mails:
function SendEmail($to,$cc,$bcc,$subject,$body) {
require( GetPHPMailPath() );
$mail = new PHPMailer();
$addresses = explode(',', $to);
foreach ($addresses as $address) {
$mail->AddAddress($address);
}
if($cc!='') {
$mail->addCustomHeader("CC: " . $cc);
}
if($bcc!=''){
$mail->addCustomHeader("BCC: " . $bcc);
}
$mail->IsSMTP();
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587;
$mail->Username = "email#email.com"; // SMTP username
$mail->Password = "password"; // SMTP password
$webmaster_email = "email"; //Reply to this email ID
$name=$email;
$mail->From = $webmaster_email;
$mail->FromName = "Service";
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = $subject;
$mail->Body = $body;
return $mail->Send();
}
How I am calling the function:
echo SendEmail($toAddress,$ccAddress,$bccAddress,$subject,$body);
The really odd part about this whole ordeal is that it is inconsistent which means there may be nothing wrong with the code but the connection to gmail?
Any ideas maybe its a php.ini problem?
This was a lag related issue.
PHPMailer functioned properly. User was sending duplicate requests. Fixed by adding comparison check with MySQL database records.