I am using cakephp 2.2
THis is my smtp setup in Config/email.php
public $gmail = array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'appmailer#someapp.com',
'password' => 'somepassword',
'transport' => 'Smtp'
);
This is my email settings.
App::uses('CakeEmail', 'Network/Email');
$email = new CakeEmail('gmail');
$email->from(array('bigshot#company.com' => 'On Behalf of Big Shot'));
$email->to('client#bigshotclient.com');
$email->subject('[Test -- please ignore] one last test. Remember to hit REPLY to this email');
$email->sender('appmailer#someapp.com');
$email->replyTo('bigshot#company.com', 'Big Shot');
$email->send('Remember to hit REPLY to this email');
WHen the email is sent, the FROM address repeatedly shows
On Behalf of Big Shot<appmailer#someapp.com>
how can i make it such that the FROM appears as the original email address of bigshot#company.com?
By the way, the replyTo works very well.
I am attempting to perfect the mail delivery that is all.
Apparently, Gmail SMTP will always overwrite the FROM field to prevent spamming.
See https://stackoverflow.com/a/3872880/80353
If anyone can help to attach the actual GMail documentation stating this point, that would be great.
Related
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.
I have a question concerning the Laravel 4.1 validators.
$validator = Validator::make(
array('name' => 'Dayle'),
array('email' => 'required|min:5|unique:users')
);
Is it possible to call a specific validation error for the case when the entered email is not unique? Reading the docs I only saw that one is able to define the error message if the validation for 'email' fails. However, if someone enters an email address but this one is already in the database it would be awesome to show the user exactly that he passed "required" but did not pass "unique".
The third parameter of Validator::make() lets you pass in an array of messages. More on this here: http://laravel.com/docs/validation#custom-error-messages
As it says in the above link, you can specify field-and-rule-specific messages by using the dot syntax email.unique. In your case this would be:
$validator = Validator::make(
array('name' => 'Dayle'),
array('email' => 'required|min:5|unique:users'),
array('email.unique' => 'This email is already being used by another user.'),
);
I'm writing a Backend System and I want to allow the users to change their email address.
I've written a custom validator to check if the email-address the user has entered already exists in my database.
Now I ran into a problem: The form is populated with the user data, so his email address is the default value of the email field. Now if the user submits the form, my validators throws an error, because (of course) this email address does already exist!
How can I solve this problem? Maybe a Validator is not the right approach to do this?
Or is there a solution to detect if the user changed the default value and fire the validator only in that case?
Hehe, that's a common problem running into validators the first time. The key is to remove that one id from the validator, inside your validator exclude the current user ID from the clause:
$validator = new Zend_Validate_Db_NoRecordExists(
array(
'table' => 'users',
'field' => 'email',
'exclude' => array(
'field' => 'id',
'value' => $id_to_edit
)
)
);
Edit: for further explanation as to what this does. It still grabs all the email adresses from the database and it still checks if there's a misconflict. If an email exists, it just ignores the email from id=$id_to_edit - so when the user changes its email but another user has that email already, the error gets thrown anyways!
I have some trouble with PEAR when I'm using the Mail_mime class to send out HTML/text mail with embedded images.
What I need script to do, is to provide an email with both a text and HTML version of the content. The content will be somewhat different.
The text version will contain some text, and an image attachment.
The HTML version will have a layout with some links and an embedded image. This image is the same as the attached image in the text version.
What I've got so far, is a script that send a plain text version and an HTML version. The text version is in fact not the text version which I'm telling it to send, but a stripped down version of the HTML email.
After some investigation, I found out that the plain text version actually gets sent in the email, but the email clients only show the stripped HTML version for some strange reason. It also seems like it's the addHTMLImage() method that breaks it. Without the embedded image the
What my code looks like, at the moment:
<?php
require 'Mail.php';
require 'Mail/mime.php';
$to = 'your#email.com';
$additional_headers = array(
'Subject' => 'Email subject',
'From' => 'my#domain.com'
);
$text_body = <<<TEXT
This is the plain text version.
TEXT;
$html_body = <<<HTML
<p>This is the HTML version</p>
<p><img src="image.jpg" alt="" /></p>
HTML;
$mime = new Mail_mime();
$mime->setTxtBody($text_body);
$mime->setHTMLBody($html_body);
$mime->addHTMLImage(file_get_contents('default.jpg'), 'image/jpeg', 'image.jpg', FALSE);
$body = $mime->get();
$headers = $mime->headers($additional_headers);
$mailer =& Mail::factory('smtp', array(
'host' => 'my.mailserver.net',
'port' => 0,
'auth' => TRUE,
'username' => 'myusername',
'password' => 'mypassword'
));
$res = $mailer->send($to, $headers, $body);
if (PEAR::isError($res)) {
echo 'Couldn\'t send message: '.$res->getMessage();
}
?>
As far as I know, there doesn't seem to be anyone else with this problem. Is there something wrong with my code, or with my PEAR installation?
Pass in the end of line character to the constructor of the Mail_mime class.
Windows in "\n\r" - or the other way around, can't remember
We ran into the same issue today and have done extensive research in to it. What we've uncovered is that Mozilla Thunderbird chokes on ABNF strings that don't follow the Content-Type capitalization pattern. In all other email clients we've tested, the text alternative worked as expected.
So, you're problem is likely your client. Hope this helps point you in the right direction.
I try to write codes about sending email using Zend Framework. Here is the code,
$mail = new Zend_Mail('utf-8');
$mailConfig = array(
'auth'=> 'login',
'username' => 'sample#gmail.com',
'password' => 'samplepassword',
'ssl' => 'tls',
'port' => '587';
$tr = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $mailConfig);
Zend_Mail::setDefaultTransport($tr);
$mail->setSubject('test email');
$mail->setBodyText('body');
$mail->setFrom('sample#gmail.com', 'Just a sample');
$mail->addTo('anothersample#gmail.com', 'Another sample');
$mail->send();
These codes work perfectly at my local computer, but failed to send email at the server side with return message "Connection time out". I guess there might be some configuration problem on the server side, but I don't know what it is. Anyone with idea what is going wrong?
Try 'ssl'='ssl' and port 995.
Contact the admin of the server and ask if they allow outgoing communication on port 587.
It seems like they are blocking certain traffic.