I want to send unique emails to multiple people (could be 1, could be 100) using PHPMailer.
$notifyemailscontent is an array that holds all the emails and names (again, could be 1 could be 100).
This below works, but I'm curious if there is a better way to do this. It seems to take a while even when there's only like 5 emails. Is there a quicker, more efficient way to do this type of thing? Or does it simply take this long if you're sending multiple emails?
/// Send notification email
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->setFrom('admin#mydomain.com', 'MyDomain');
$mail->addReplyTo('admin#mydomain.com', 'MyDomain');
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = "FYI, there's a new entry!";
foreach($notifyemailscontent as $email => $name) {
$mail->addAddress($email, $name);
$mail->Body = "Hi $name!<br><br>
We're just letting you know that there is a new entry. To see it, click the link below:<br><br>
<a style='background: blue; color: white;' href='http://myfulldomain'>the pool name</a>
";
$mail->AltBody = "";
$mail->send();
$mail->ClearAddresses();
}
Related
My apologies, I am very new and had difficulty with the editing process etc. I hope the following is more acceptable. The PHP application attaches to the 'receiving email box' and processes the received emails accordingly. It creates a new email that contains comments, attaches the original email and then sends the newly created email back to the 'from address' extracted from the original email. The original email may have been sent from any number of email programs available to users. It may also have pdf/text attachments. When I send the 'newly' created email to Gmail, it displays the attached original email (and it's attachments if any) correctly but not when it is sent to MS Outlook or Horde.
After execturing a new phpmailer class, I added the following:
$mail->CharSet = 'UTF-8';
$mail->Encoding = 'base64';
Coding to save the original email:
$mime = imap_fetchbody($inbox, $email_number, "");
file_put_contents('./workfolder/OriginalEmail.eml', $mime);
I have also tried this coding when saving the original email:
$headers = imap_fetchheader($inbox,$email_number, FT_PREFETCHTEXT);
$body = imap_body($inbox, $email_number);
$structures = imap_fetchstructure($inbox, $email_number);
file_put_contents('./workfolder/OriginalEmail.eml', $headers . '\n' . $body . '\n' . $structures);
I have checked the mime type which displays: message/rfc822
Coding used to attach original email:
$mail->AddAttachment('./workfolder/OriginalEmail.eml');
I have also tried this when attaching the original email:
$mailer->AddAttachment('./workfolder/','OriginalEmail.eml','base64','message/rfc822');
Wednesday - I am having such problems with adding comments.
Here is what I tried:
$strOrigEmail = file_get_contents('./workfolder/OriginalEmail.eml');
echo '<BR><BR>$strOrigEmail: ' . $strOrigEmail;
$mail->addStringAttachment('$strOrigEmail', 'YourEmail.eml');
And the echo displays everything from the original email- headers, body etc. and the attachments (including their filename) but it is endocded. Below is a snippet below of what it looks like:
name=junk.txt Content-Disposition: attachment; size=11; filename=junk.txt junk file --=_7-AofrqAv83eu5i63j73DWn--
I have also tried this and no better - displays same thing as above:
$strOrigEmail = file_get_contents('./workfolder/OriginalEmail.eml');
echo '<BR><BR>$strOrigEmail: ' . $strOrigEmail;
$mail->addStringAttachment(base64_decode('$strOrigEmail'), 'YourEmail.eml');
I am building a quote system, the quote system sends out the quote to multiple people with a personalised message via email. I am using the following code to do so:
$mail = new PHPMailer();
$mail->AddReplyTo("myAddress#domain.com", "Company");
$mail->SetFrom('quotes#company.com', 'COMPANY');
// Set each of the recipients
$users = $quote->GetClients();
foreach($users as $user)
{
$mail->AddAddress($user["Email"], $user["Name"]);
}
$mail->Subject = "Hello" . $users[0]["Name"];
$body = "This is your personal Email";
$mail->MsgHTML($body);
$mail->Send();
The problem being is that, when I send this email, it sends to all the recipients that it should, but it includes all of the recipients names. Whereas, I just want to display for that particular person. I.e. If I get an email, it would be: "Hello Phorce, This is your Personal Email" but instead I get "Hello {user1} {user2} {user3}" and this is not what I want.
Is it possible to do what I am trying to do using PHPMailer?
I am sending mail via PHP Mailer. http://phpmailer.worxware.com/
I want to be able to set the From to one emailand the REPLY-TO to another email and the RETURN-PATH to yet another.
Mainly.. I want the bounced emails to go to something like BOUNCEDemails#bademail.com
I was hoping the RETURN PATH could do this.
And if a user who gets the email I don't want them to see its from BOUNCEDemails etc.. to I want to give them an option to reply to a real email address.
I need the bounced emails tho to go to a seperate email because I don't want the REPLY TO to get many bad emails. etc..
HERE IS WHAT I HAVE: Does Not work
$mail->AddAddress('ed#RealEmail.org', 'John Doe');
$mail->AddReplyTo('replytoMe#email.com', 'Reply to email');
$mail->SetFrom('mailbox#email.com', 'From Name and Email');
$mail->AddCustomHeader('Return-path: BOUNCEDemails#bademail.com');
The code above replies to SetFrom and sends all bounces to SetFrom. Any ideas how to separate the two? Thanks
the correct way to set this (as of july 2013) is by using:
$mail->ReturnPath='bounce_here#domain.com';
the phpmailer source contains the following, which is fairly self explanatory:
if ($this->ReturnPath) {
$result .= $this->HeaderLine('Return-Path', '<'.trim($this->ReturnPath).'>');
} elseif ($this->Sender == '') {
$result .= $this->HeaderLine('Return-Path', '<'.trim($this->From).'>');
} else {
$result .= $this->HeaderLine('Return-Path', '<'.trim($this->Sender).'>');
}
You may use
$mail->AddReplyTo('name#yourdomain.com', 'First Last');
$mail->AddReplyTo('replytoMe#email.com', 'Reply to email');
$mail->AddAddress('ed#RealEmail.org', 'John Doe');
Notice the order! AddReplyTo has to be BEFORE AddAddress!!!
I have developed a competition page for a client, and they wish for the email the customer receives be more than simply text. The tutorial I used only provided simple text, within the 'send body message'. I am required to add html to thank the customer for entering, with introducing images to this email.
The code is:
//send the welcome letter
function send_email($info){
//format each email
$body = format_email($info,'html');
$body_plain_txt = format_email($info,'txt');
//setup the mailer
$transport = Swift_MailTransport::newInstance();
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance();
$message ->setSubject('Thanks for entering the competition');
$message ->setFrom(array('info#examplemail.com' => 'FromEmailExample'));
$message ->setTo(array($info['email'] => $info['name']));
$message ->setBody('Thanks for entering the competition, we will be in touch if you are a lucky winner.');
$result = $mailer->send($message);
return $result;
}
This function.php sheet is working and the customer is recieving their email ok, I just need to change the
('Thanks for entering the competition,
we will be in touch if you are a lucky
winner.')
to have HTML instead...
Please, if you can, provide me with an example of how I can integrate HTML into this function.
You can also just add 'text/html' to setBody (ref):
->setBody($this->renderView('YouBundleName:Default:email.html.twig'), 'text/html');
$message = Swift_Message::newInstance();
$message->setContentType('text=html');
Will the same text remain or should it be styled somehow?
Editing your emails in html requires inline css styles eg:
('<p style="font-size:1.2em; color:#f0f0f0;">Thanks for entering the competition, we will be in touch if you are a lucky winner.</p>')
if you need a table just add:
('<table style="font-size:1.2em; color:#f0f0f0;"><tr><td>Thanks for entering the competition, we will be in touch if you are a lucky winner.</td></tr></table>')
or to make it more simpler
$message_body'
<table style="font-size:1.2em; color:#f0f0f0;">
<tr>
<td>Thanks for entering the competition, we will be in touch if you are a lucky winner.</td>
</tr>
</table>
';
$message ->setBody($message_body);
I know that when I need to send html emails I need to set the content-type to html which I believe you did on the following line
$body = format_email($info,'html');
I hope this is what you were looking for. if not let me know
I'm trying to get Zend_Mail to send an encapsulated message - as though it's forwarding an email.
$attachedContent = "<h1>H1 Email</h1>";
$emailContent = "<h1>Email Content>";
$mail = new Zend_Mail();
$mail->setBodyText('text content');
$mail->setBodyHtml($emailContent);
$mail->setFrom('kieran#fromz.com.au', 'GAS');
$mail->addTo('kieran#fromz.com.au', 'GAS');
$at = $mail->createAttachment($attachedContent);
$at->type = 'message/rfc822;
name="forwarded message"';
$at->disposition = Zend_Mime::DISPOSITION_INLINE;
$at->encoding = Zend_Mime::ENCODING_7BIT;
$mail->setSubject('Test');
$mail->send();
Mail clients are getting the email, rendering the normal HTML content, and displaying the forwarded message and rendering its contents, however, it's formatting like:
<h1>Email Content</h1>
Can you see what I'm doing wrong? I've not found anything online, and have tried my best to copy the formatting from looking at email source.
Cheers,
Kieran
maybe these lines are causing it??
$attachedContent = "<h1>H1 Email</h1>";
$emailContent = "<h1>Email Content>";