I working on a form whereby when the user enter in their email account and click on send, an email will be sent to their email account.
I have everything worked out. Just that it doesnt send the email to my account. Anyone have any ideas? Is there a configuration that I left out or something?
This is the sample from my controller:
public function retrieveemailAction(){
$users = new Users();
$email = $_POST['email'];
$view = Zend_Registry::get('view');
if($users->checkEmail($_POST['email'])) {
// The Subject
$subject = "Email Test";
// The message
$message = "this is a test";
// Send email
// Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.
// Use if command to display email message status
if(mail($email, $subject, $message, $headers)) {
$view->operation = 'true';
}
} else {
$view->operation = 'false';
}
$view->render('retrieve.tpl');
}
First of all i would switch to using Zend_Mail. Second i would use a real mail account on an smtp server somewhere and send from that. A lot of times there are restrictions on sending from the server itself, but using an actual mail server usually fixes this.
I recommend you use
Zend_Mail
instead ofmail()
. It handles a lot of stuff automatically and just works great.Do you have a SMTP server? Trying to send mail without your own SMTP server could be causing the mail to not be sent.
This is what I use for sending mails using
Zend_Mail
and Gmail:In
Bootstrap.php
, I configure a default mail transport:Then to send an email I use the following code:
There's a very useful screencast covering Zend_Mail available on ZendCasts http://www.zendcasts.com/introduction-to-zend_mail/2010/02/
In line
$mail->setBody($message);
, change it to$mail->setBodyText($message);