customize from address of email - email

I am using Laravel 4.2. I don't want the default 'from address' which is given in config->mail.php file to be used everywhere in my application. I need to use another 'from address' on another page. How can I do this?
$emails = [$formData["inputEmail"]];
Mail::send('emails.testview', array('formData'=>$formData), function($message) use ($emails){
$message->from('test#example.com', 'test');
$message->to($emails)->subject('test subject');
});

Related

My template emails always send as plain text not HTML

I'm new to SendGrid and I'm trying to work out why the emails are always sent as plain text instead of the designed HTML transactional template I've made. If I use the sendgrid "preview/test" feature to send myself the email, it comes through looking exactly how it should, images, HTML etc.
However, when I use the PHP API to send the email, the email is sent but only in plain text. I use this line to tell SendGrid which template to use:
$mail->setTemplateId([my template ID]);
Are there some other things I should be setting via the PHP API before I finally call the following?
$sg->client->mail()->send()->post($mail);
Below is all my SendGrid code:
$from = new SendGrid\Email([website name], [website email address]);
$subject = "test subject";
$to = new SendGrid\Email(null, $email);
$content = "";
$mail = new SendGrid\Mail($from, $subject, $to, $content);
$mail->setTemplateId([my template ID]);
//$mail->setASMGroupId(3057);
$mail->personalization[0]->addSubstitution("%email%", $email);
$mail->personalization[0]->addSubstitution("%hash%", $hash);
$apiKey = [my api key];
$sg = new \SendGrid($apiKey);
$response = $sg->client->mail()->send()->post($mail);
I dont put anything in for the $content because the content is dictated in the template.
If anyone has any idea why it's only sending a plain text version of my templated email when sent from PHP, any advice would be much appreciated.
Thank you
EDIT
I thought I might have to set the content-type in the header so I added:
$mail->addHeader("Content-Type", "text/html");
But this just gives me an error. Is there something I'm missing?
To force the email to be treated as HTML, just add an empty HTML body to the message:
$mail->setHtml(" ");
$mail->setText(""); //Sendgrid requires a plain-text body too
You can also use
$content = new \SendGrid\Content("text/html", "<html><body>some text here</body></html>");
$mail = new \SendGrid\Mail($from, $subject, $to, $content);
as shown in the example code:
https://github.com/sendgrid/sendgrid-php/blob/master/examples/helpers/mail/example.php

Cakephp : add more recipients before send an email

I have to send an email to several recipients, but only if my current email address is marked as 'out of office'. In order to do that I will need to check the condition before sending the email and to retrieve my backups and add them in $to .
I currently managed to find a quick fix, I've modified CakeEmail, but it seems a little wrong to alter this file.
Any ideea of how I can do this without modifying CakeEmail?
Thank you,
In your configuration (core.php) file you create a new configuration
Configure:write( 'notify_people', array( 'email1#example.com' => 'Email1', 'email2#example.com' => 'Email2' );
Then you use the CakeEmail::to() to add recipients before sending an email. So you update all your $email->to() calls to read the configuration value instead.
$email = new CakeEmail();
$email->to( Configure::read( 'notify_people' ) );
//TODO: configure sender, subject etc...
//finally send the email
$email->send( $bodyOfTheMessage );
When you need to change the list of recipients you only have to do it once in the configuration file.

How can I send email Headers using Amazon SES?

I am using a Wrapper from http://sourceforge.net/projects/php-aws-ses/
I am not able to send Email Headers with
From: Name <email#example.com>
Is there any way we can send headers using amazon ses. Any other PHP Wrapper you recommend which allows us to do that?
Change the FROM Variable to something like this
$m->setFrom(" Name <info#gitgrow.com>");
For the new API SDK (v2) you can use:
$client->sendMail( array(
'source' => 'Name <a#b.c>',
....
)
);
Basically if you want to include the name, the source must have the name followed by the email id and importantly, the email id must be enclosed in < and >

Sending e-mail programmatically in Magento is failing

Why is there nowhere in the Configuration/System/Mail Sending Settings to specify a user name and password for your smtp server?
To get around this, do you need to make the changes to getMail() outlined in this post:
http://www.magentocommerce.com/boards/viewthread/1073/P30/
I want to do something very simple:
- create an e-mail template
- do not have to make reference to that template in any config files.
- programmatically send an e-mail using the template defined above
- supply values to replace any tags in the template
- supply recipient e-mail addresses
- supply other bits, like a from address
So first step - create a template.
- In Confguration/Transactional Emails I believe I am supposed to see a list of templates. I see nothing. But if I add a new template, I can select from a list of templates.
- Give template a name of "Bob".
- Add a few vars to the template:
myvar1={{var myvar1}}
myvar2={{var myvar2}}
- Save the template; it is given an Id of 1.
Now send the e-mail programmatically from a controller action:
- No need to make change to LINEEND in Mime.php as it is already set to \n in version 1.4.2.0
- Make changes to getMail() in Template.php as specified in this post: http://www.magentocommerce.com/boards/viewthread/1073/P30/
- Write code in the controller action to send the e-mail:
This returns nothing:
$emailTemplate = Mage::getModel('core/email_template')->loadDefault('no matter what goes here emailTemplate is not set');
This does return an email template:
$emailTemplate = Mage::getModel('core/email_template')->loadByCode('Bob');
but the call to send below fails:
$emailTemplate->setSenderEmail('sent#byme.com');
$emailTemplate->setSenderName('Steve');
$emailTemplateVariables = array();
$emailTemplateVariables['myvar1'] = 'TestValue1';
$emailTemplateVariables['myvar2'] = 'TestValue2';
// $processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables); -- this returns nothing
$emailTemplate->send('thisisme#mydomain.com','John', $emailTemplateVariables);
In the system.log I get the warning below, and no e-mail ever arrives.
Warning: stream_socket_enable_crypto() [<a href='streams.crypto'>streams.crypto</a>]: this stream does not support SSL/crypto in C:\Applications\Apache Software Foundation\Apache2.2\htdocs\magento\lib\Zend\Mail\Protocol\Smtp.php on line 206
Should I be using loadByCode? I wish there was some worthwhile documentation (the help for loadByCode is "Load template by code" !!). Should I be using send, sendTransactional? Oh for a bit of quality documentation.
Thanks
I see 2 questions here.
1. How to configure Magento mailing system to use smtp protocol ?
You are having trouble for this because Magento is made to use default host mailing. So it will search for it on the machine where it is installed.
If you want to configure a smtp server, I would recommend using this extension : http://www.magentocommerce.com/magento-connect/ziq2004/extension/460/advanced-smtp--artson.it
I found it simple to use and configure.
2. How to send a mail in your custom module
You can first create your template in Confguration/Transactional Emails, mark down the Id for it will be your identifier
Then, simply use this code to send the mail in your module
<?php
// The Id you just marked...
$templateId = 1;
// Define the sender, here we query Magento default email (in the configuration)
// For customer support email, use : 'trans_email/ident_support/...'
$sender = Array('name' => Mage::getStoreConfig('trans_email/ident_general/name'),
'email' => Mage::getStoreConfig('trans_email/ident_general/email'));
// Set you store
// This information may be taken from the current logged in user
$store = Mage::app()->getStore();
// In this array, you set the variables you use in your template
$vars = Array('my_var' => $my_var,
'another_var' => 12);
// You don't care about this...
$translate = Mage::getSingleton('core/translate');
// Send your email
Mage::getModel('core/email_template')->sendTransactional($templateId,
$sender,
'recipient#gmail.com',
'Recipient Name',
$vars,
$store->getId());
// You don't care as well
$translate->setTranslateInline(true);
?>
Hope this will help you
Regards,
I took out the 'ssl' => 'tls' element in the array in getMail() in Template.php and my e-mail came through.
I'd still appreciate if anyone has an explanation of how the smtp server's username and password should be specified, and an explanation of the differences in the template load methods etc would be most welcome!
If anyone is looking for full sample code of how to send a Magento email based on an existing Magento email template, the following works well. It does not require any XML config. You can load the template by name as well as by ID. In this case I load it by name.
// This is the name that you gave to the template in System -> Transactional Emails
$emailTemplate = Mage::getModel('core/email_template')->loadByCode('My Custom Email Template');
// These variables can be used in the template file by doing {{ var some_custom_variable }}
$emailTemplateVariables = array(
'some_custom_variable' => 'Hello World'
);
$processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);
$emailTemplate->setSenderName('Joe Bloggs');
$emailTemplate->setSenderEmail('test#test.com');
$emailTemplate->setTemplateSubject("Here is your subject");
$emailTemplate->send('recipient#test.com', 'Joanna Bloggs', $emailTemplateVariables);

How to rewrite or set the Return-Path in cakePHP Email Component?

I'm using the cakePHP email component for sending mails from my application. Now the return-path has something like www#domain.tld
How can I set or rewrite the Return-Path value in emails when using the cakePHP Component?
I know how to do it when sending mails via 'mail' in PHP but the cakePHP email component seems to missing such a feature... or am I missing something? :)
In CakePHP 2 (where the Email Component is largely replaced by the CakeEmail class), you can do this configuration inside /app/Config/email.php:
class EmailConfig {
public $email = array(
...
// The next line attempts to create a 'Return-path' header
'returnPath' => 'myaddress#mydomain.com',
// But in some sendmail configurations (esp. on cPanel)
// you have to pass the -f parameter to sendmail, like this
'additionalParameters' => '-fmyaddress#mydomain.com',
...
);
}
Or if you need to do it just for a single email, something like this should work...
App::uses('CakeEmail', 'Network/Email');
$email = new CakeEmail('MyConfig');
$email->from(...)
->to(...)
->subject(...)
->returnPath('myaddress#mydomain.com')
// Haven't tested this next line, but may possibly work?
->config(array('additionalParameters' => '-fmyaddress#mydomain.com'))
->send();
There's an attribute called EmailComponent::return that is the return path for error messages. Note that this is different than the replyTo attribute.
$this->Email->return = 'name#example.com';
http://book.cakephp.org/1.3/en/The-Manual/Core-Components/Email.html
A co-worker and I were working on this same issue, we found that editing the following line in php.ini gave us our fix:
from:
sendmail_path = /usr/sbin/sendmail -t -i
to:
sendmail_path = /usr/sbin/sendmail -t -i -f youremail#address
when testing be sure to send your emails to a valid domain. this caught us for a few minutes.
To change the return path in CakePHP Email component I do like this:
...
$return_path_email = 'return#email.com';
...
$this->Email->additionalParams = '-f'.$return_path_email;
and it works like charm ;)
Digging into the cake manual when you were looking at how to use the rest of the component you should have seen something like the following. This is what set the Return-Path.
$this->Email->return = 'name#tld.com';