Best way to use an email signature with CodeIgniter Email Class - php

How can I add an signature to emails I send using CodeIgniter's Email Class, for example add the following at the bottom of each email:
Joe Bloggs, Company, City, Tel Number

I'd use views for this functionality.
In your views, you can add your signatures directly:
// views/email_message.php
<h1>My Email Message</h1>
<p>Content</p>
<hr />
<p>Joe Bloggs, Company, Blah</p>
Or, better yet, I'd create a signature view and pass the data to it:
// views/email_message.php
<?= $this->load->view('email/message', $message_data(), TRUE) ?>
<?= $this->load->view('email/signature', $signature_data(), TRUE) ?>
Either way, you can pass this to your email message:
// in your controller
$message = $this->load->view('views/email_message', $data(), TRUE);
// configure email options, etc.
...
$this->email->message($message);
// send the email

I would do something like this for simplicity:
$this->email->message('Whatever your message is.' . '\n\n Joe Bloggs, Company, Blah');

Related

HEREDOC text and variables formating issue

I created a PHP script that collects variables from HTML and converts them to PHP variables. Then takes those variables and inserts them into a HEREDOC string and finally sends an email to a predefined person. I'm having an issue getting the text to format with a carriage return after each variable. So that all the text in the email is left side formatted.
What I am getting is this:
SFARC Membership Application Date: February 19th. 2019 First Name: XXXXXX Last Name: XXXXXXX Nick Name: XXXXXXX
Here is portion of my code that handles the text string:
// Generate application in a message
$message = <<<EOT
SFARC Membership Application
Date: $App_Date
First Name: $First_Name
Last Name: $Last_Name
Nick Name: $Nick_Name
Address: $Address
City/Town: $City_town
Zip Code: $Zip_code
Email: $Email
Home Phone: $Home_phone
Cell Phone: $Cel_phone
Callsign: $Call_sign
ARRL Member: $Arrl_member
Membership Type: $Membership_type
Membership Term: $Membership_term year(s)
Payment Method: $Payment_method
Membership Dues: $Membership_dues
EOT;
// Sending email
if(mail($to, $subject, $message, $headers )){
echo 'Your membership application has been successfully submitted.';
} else{
echo 'Unable to submit your membership application. Please try
again.';
};
?>
Godaddy is who is hosting my website. Is that the issue? I watched several youtube videos and I have no idea what I am missing? Is there a better way to code to achieve the results I am looking for?
Thanks in advance.
I think your message is send by HTML reason. You can confirm it by content type in the header of email. Or add $message = nl2br($message); before send and try again.
You probably tried this, but I want to double check: did you try putting \n or \r at the end of lines?

send HTML markup from Custom Field to the Email Campaign

I have an E-commerce website and is integrated to InfusionSoft
What currently happening is that...
Customer completes an order on my website and purchases, let say 2 products.
Upon Order Completion, Order Received tag is added and customer's info is added to InfusionSoft, and the Order Detail HTML Markup (which is generated on my website via code) is added to a Custom Field, ~_myCustomField~
There is already a campaign running which send simple Thank You Email to customer.
What I want is that I can send the Order Detail(which is stored in ~_myCustomField~) along with the Thank You Email
What I have tried that, I have added the custom field into Campaign's Email just like ~Contact._myCustomField~ but it sends the only HTML, not generated one!
_myCustomField contains for example
<table>
<tr>
<td>This is your order detail</td>
</tr>
</table>
Instead of saving the HTML into a custom field, you can just send the thank you email at that point.
You can use the email service to send an email:
https://developer.infusionsoft.com/docs/read/Email_Service
example:
$title = "template API test";
$category = "API Category";
$fromAddress = "from#infusionsoft.com";
$toAddress = "~Contact.Email~";
$ccAddress = "";
$bccAddresses = "";
$subject = "My Fancy Subject Line";
$textBody = "This is the text email body";
$htmlBody = "HTML"
$contentType = "Contact";
$mergeContext = "";
$tmpId = $app->addEmailTemplate($title, $category, $fromAddress, $toAddress, $ccAddress, $bccAddresses, $subject, $textBody, $htmlBody, $contentType, $mergeContext);
If you want to keep the interaction with the campaign, you can use the goal feature. Learn more about goals here.
You will be after the funnel service to see if a goal has been completed (such as an order) and send the Thank you email at that point.

PHP Mailer --- Reply-to: --- Return-path --- SetFrom

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!!!

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

What is the best way to use Email Template in Zend/PHP

I am working on a website where Users create their accounts. I need to send email to users on many oceans. For example when signup, forgot password, order summary etc. I want to use emails templates for this. I need your suggestions for this. I want to use a way that If I change any email template or login in less time and changes.
I have thought about the following way:
I have a table for email templates like this:
id
emailSubject
emailBody
emailType
For example when user forgot password:
id:
1
emailSubject:
ABC: Link for Password Change
emailBody:
<table border=0>
<tr><td>
<b> Dear [[username]] <b/>
</td></tr>
<tr><td>
This email is sent to you in response of your password recovery request. If you want to change your password, please click the following link:<br />
[[link1]]
<br/>
If you don't want to change your password then click the following link:<br/>
[[link2]]
</tr></td>
<tr><td>
<b>ABC Team</b>
</td></tr>
</table>
emailType:
ForgotPassword
Prepare email data:
$emailFields["to"] = "user#abc.com";
$emailFields["username"] = "XYZ";
$emailFields["link1"] = "http://abc.com/changepassword?code='123'";
$emailFields["link2"] = "http://abc.com/ignorechangepasswordreq?code='123'";
$emailFields["emailTemplate"] = "ForgotPassword";
Now Pass the all fields to this function to send email:
sendEmail( $emailFields ){
// Get email template from database using emailTemplate name.
// Replace all required fields(username, link1,link2) in body.
// set to,subject,body
// send email using zend or php
}
I planed to use above method. Can you suggest better way or some change in above logic.
Thanks.
I'd use Zend_View. Store your templates in /views/email/EMAILNAME.phtml, create a Zend_View object with the required email template and pass it the required data.
Off the top of my head, so untested... but something similar should work:
$view = new Zend_View();
$view->setScriptPath( '/path/to/your/email/templates' );
$view->assign( $yourArrayOfEmailTemplateVariables );
$mail = new Zend_Mail();
// maybe leave out phtml extension here, not sure
$mail->setBodyHtml( $view->render( 'yourHtmlTemplate.phtml' ) );
$mail->setBodyText( $view->render( 'yourTextTemplate.phtml' ) );
As previously mentioned, Zend_View is the way. Here is how I do this:
$template = clone($this->view);
$template->variable = $value;
$template->myObject = (object)$array;
// ...
$html = $template->render('/path/filename.phtml');
Use Markdownify to covert to plain text:
$converter = new Markdownify_Extra;
$text = $converter->parserString($html);
Setup mail:
$mail = new Zend_Mail();
$mail->setBodyHtml($html);
$mail->setBodyText($text);
Then setup Transport and send.

Categories