Zend_Mail bug emailing with $mail->setReplyTo - php

Why does setReplyTo($reply_to_mail) send email to $reply_to_mail? Shouldn't it just add email adress to reply-to field in the email message?
Currenyly if sending mail from website form and filling reply-to field, message sends to reply-to email and to our admin email.
Why does it duplicates email? Should send only to our admin email.
class Helper_Mail extends Zend_Controller_Action_Helper_Abstract
{
public function direct($email,$from,$message,$title,$replyto='')
{
$this->sendmail($email,$from,$message,$title,$replyto);
}
private function sendMail($email,$from,$message,$title,$replyto)
{
/* Configuring SMTP settings */
$config = array(
'auth' => 'login',
'ssl' => 'tls',
'username' => 'adminmail#gmail.com',
'password' => 'password',
'port' => 587);
$smtpHost = new Zend_Mail_Transport_Smtp('smtp.gmail.com',$config);
Zend_Mail::setDefaultTransport($smtpHost);
$mail = new Zend_Mail('UTF-8');
$mail->setBodyHtml($message);
$mail->setFrom('adminmail#gmail.com', $from);
$mail->addTo($email);
$mail->setSubject($title);
if(!empty($replyto))
{
$mail->setReplyTo($replyto);
}
try
{
$mail->send();
}
catch(Zend_Mail_Exception $e)
{
echo $e->getMessage();
}
}
}

You can use Zend_Mail::setReplyTo() if you are using a version of Zend > 1.8
If not (<= 1.8) you should use Zend_Mail::addHeader('Reply-To', 'replymail#example.com')

It was a bug, fixed in new versions. ;)

Related

Sending email does not work when I use my helper in Yii php

I'm using Yii framework while my question is probably intended to PHP expert.
I have created a controller to send email from my web application, it works fine.
Given that, I intend to use email in several sontrollers in my app, I wanted to created a helper but that does not work. Email is not sent. (I'm using swiftmailer)
The code of the working controller is the following:
<?php
class MailController extends Controller
{
/**
* Declares class-based actions.
*/
public function actionSendemail() {
// Plain text content
$plainTextContent = "This is my first line ;-)\nThis is my second row of text";
// Get mailer
$SM = Yii::app()->swiftMailer;
// New transport mailHost= localhost, mailPort = 25
$Transport = $SM->smtpTransport(Yii::app()->params['mailHost'], Yii::app()->params['mailPort']);
// Mailer
$Mailer = $SM->mailer($Transport);
// New message
$Message = $SM
->newMessage('My subject')
->setFrom(array('test1#localhost.localdomain' => 'Example Name'))
->setTo(array('myemail#domain.com' => 'Recipient Name'))
// ->addPart($content, 'text/html')
->setBody($plainTextContent);
// Send mail
$result = $Mailer->send($Message);
}
}
The helper code is the following
<?php
// protected/components/Email.php
class Email {
public static function sendEmail($subject, $from, $to, $body)
{
// Get mailer
$SM = Yii::app()->swiftMailer;
// New transport
$Transport = $SM->smtpTransport(Yii::app()->params['mailHost'], Yii::app()->params['mailPort']);
// Mailer
$Mailer = $SM->mailer($Transport);
// New message
$Message = $SM
->newMessage($subject)
->setFrom(array($from => 'Example Name'))
->setTo(array($to => 'Recipient Name'))
// ->addPart($content, 'text/html')
->setBody($body);
// Send mail
$result = $Mailer->send($Message);
}
}
the way I call it is the following
$subject= 'My subject';
$from = Yii::app()->params['adminEmail']; // adminEmai is a globalparam like above controller
$to='xxxx#xxx.com';
$body='my body';
Email::sendEmail($subject, $from, $to, $body);
when I run this code, I have no error, but I dont receive the email.
Thank you for your help.
I found my error.
my global parameters in config.php was not set correctly.
So content I put in the from field was not recognized by my hmailserver which is configured for the moment with the content test1#localhost.localdomain
sorry for the question and thanks

Accept email address from user and send email to that address

public function send_mail() {
$this->email->from('your#email.com', 'My Name');
$this->email->to('to#email.com');
$this->email->cc('cc#email.com');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
echo $this->email->print_debugger();
}
i'm trying out the codeigniter email func but i cant seem to receive the test mail, but it saids that it has successfully send the mail but there's none,
new to ci so i'm confused about this problem, $this->load->library('email'); is also loaded,
anyhelp thanks!
EDIT
ok guys thanks for the answer i have added the ff code and it now works,
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'your email',
'smtp_pass' => 'your password'
);
Now my question is how will I edit the codes above to accept the "to" email from the user?
okay i did the "to" part already, and its like this
$this->email->to($point->email);
need help again with the "message" part, i need to put data from the user in the "message" part, i tried what i did in the "to" part but it only accepts one item, i need multiple items, thanks
In the section where you're calling the function send_mail(), pass the email address and other data as well, as arguments to the function; something like this:
$to = $point->email;
$msg = $point->message; // the message part
$phone = $point->phone; // phone number
$address = $point->address; // postal address
$this->send_email($to, $msg, $phone, $address);
And then slightly modify the send_mail() function as:
// $to_address will contain the value stored in $to, i.e. "abc#def.com" in this case
public function send_mail($to_address, $body_message, $phone_no, $addr) {
// can make use of extra data like phone number, address in here
$this->email->from('your#email.com', 'My Name');
$this->email->to($to_address);
$this->email->message($body_message);
.
.
.
}
It works fine in my linux server without any $config.
Please read this to set another protocol

Is there a cleaner code for the PHPmailer in wordpress..?

As a extended version to this question : PHPMailer(): Called Mail() without being connected
Can't we use all the configurations for the PHPmailer in an array, Some thing like this:
$mail = array(
'SMTPAuth' => true,
'Host' => 'smtp.millicenthotel.com',
'Port' => 25,
'Username' => 'info#millicenthotel.com',
'Password' => 'gboskeritysoldier1'
);
I tried something like this and it not work. I'm looking for a cleaner way of doing this.
Thanks in Advance.
you have an action hook called phpmailer_init
from codex :
The wp_mail function relies on the PHPMailer class to send email
through PHP's mail function. The phpmailer_init action hook allows you
to hook to the phpmailer object and pass in your own arguments.
example ( codex again ):
add_action( 'phpmailer_init', 'my_phpmailer_example' );
function my_phpmailer_example( $phpmailer ) {
$phpmailer->IsSMTP(); //switch to smtp
$phpmailer->Host = 'smtp.example.com';
$phpmailer->Port = 25;
$phpmailer->Username = 'yourusername';
$phpmailer->Password = 'yourpassword';
}

CakeEmail not sending, but no errors

I'm pretty new to CakePHP and this is my first attempt setting up an email form.
Keeping the example simple:
<?php
App::uses('AppController', 'Controller');
App::uses('CakeEmail', 'Network/Email');
class EmailController extends AppController {
public function send_email($from, $subject, $message) {
$Email = new CakeEmail();
$Email->from($from)
->to('[my personal email]')
->subject($subject);
if($Email->send($message)) {
$result = 'Your email has been sent.';
} else {
$result = 'Your email failed to send.';
}
$this->set('result', $result);
$this->set('params', '('.$from.'|'.$subject.'|'.$message.')');
}
}
send_email.ctp
<?php echo $result;?>
<br>
<?php echo $params;?>
I'm getting "Your email has been sent.", the $params look as I expect, and I am not seeing any errors... but I'm not getting the email. Any idea why this might happen?
Before this you need to define Email configuration in email.php under Config folder
Here we have gmail configuration for example
class EmailConfig {
public $gmail = array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'username#gmail.com',
'password' => '*****',
'transport' => 'Smtp'
);
}
then you can use this setting in controller like
$Email= new CakeEmail('gmail');
Inshort you have to configure SMTP according to requirement. I hope this will be handy for you. Thanks

How to fix [SocketException] Could not send email. Error in CakePHP

I have been trying to get this Email code working in my CakePHP for ages now. It is meant gather data from a simple contact form and send an email to a specific address. For now I am simply trying to get the emailing sending.
When I load the page I get Could not send Email and when I look at the log I get [SocketException] Could not send email.
Also I have used the smtp settings in a different area for a reset password email that does work.
Any help would be greatly appreciated.
Here is my ContactController
<?php
App::uses('AppController', 'Controller');
App::uses('CakeEmail', 'Network/Email');
class ContactController extends AppController {
public function sendEmail()
{
/*$fname = $_POST['first_name'];
$lname = $_POST['last_name'];
$visitor_email = $_POST['email'];
$telephone = $_POST['telephone']; */
// $comments = $_POST['comments'];
$Email = new CakeEmail();
/* SMTP Options */
$Email->smtpOptions = array(
'transport' => 'Smtp',
'port'=>'465',
'timeout'=>'30',
'host' => 'ssl://smtp.gmail.com',
'username'=>'frankstoncsf#gmail.com',
'password'=>'xxxxxxx',
'log'=>true
);
$Email->template = 'resetpw';
$Email->from(array('frankstoncsf#gmail.com' => 'My Site'));
$Email->to('thomas.chambers5#gmail.com');
$Email->subject('Reset Your Frankson.net User Password');
$Email->sendAs = 'both';
$Email->delivery = 'Smtp';
// $Email->set('ms', 'hello');
$Email->send('hello');
set('smtp_errors', $Email->smtpError);
}
public function index() {
$this->sendEmail();
}
}

Categories