Adding an encapsulated email (like a forwarded email) from Zend Mail - php

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

Related

PHPMailer and attachments not displaying properly when opened

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');

Multiple emails with unique content PHP mailer?

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();
}

PHPMailer - Sending to multiple address but unique content

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?

can anyone help me with mail function in php?

I'm new to php, i just start to use mail function. I have a problem like below:
Suppose, i have more recipients than one that will get my email.
<?php
$to = $_POST['to']; //xxxxx#yahoo.com,yyyyy#yahoo.com,zzzzz#yahoo.com
$from = $_POST['from']; //aaaaa#yahoo.com
$from = "myinfo <$from>";
$subject = $_POST['subject']; //New campiagn
$content = $_POST['content'];
$headers = "From:" . $from;
mail($to,$subject,$content,$headers);
?>
The code above work correctly. But when user get this email, they will see:
To Me, yyyyy#yahoo.com, zzzzz#yahoo.com
I don't want all users that get this email show when user view this email. Below is what i want:
To myuser#info.com
Does it is possible to do like this? I'm appreciate to all of your answer :)
Thank in advance
If you use a list in the To: field of a regular mail client the list will appear to every recipient. This is normal behaviour. If you want to hide the list then your best option is to send each recipient their own individual copy.

How can I add HTML formatting to 'Swift Mail tutorial based' PHP email?

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

Categories