I created a contact form in my website, and, for send the e-mails to website account (contact#mywebsite.com), I'm using gmail smtp, using the same e-mail that I'll receive the messages.
So, users go to my website, click in contact page, fill the form with:
Name, Email, Message.
Than I send the email with the following code:
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'contact#mywebsite.com',
'smtp_pass' => 'mypass',
'mailtype' => 'html',
'charset' => 'utf-8'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$email = $this->input->post('email');
$name = $this->input->post('name');
$msg = $this->input->post('msg');
$this->email->to('contact#mywebsite.com');
$this->email->reply_to($email); //User email submited in form
$this->email->from($email, $name);
$this->email->subject('Conctact form');
$this->email->message($msg);
if ($this->email->send())
{
return true;
} else
{
echo $this->email->print_debugger();
return false;
}
The e-mail goes to my inbox in "contact#mywwebsite.com", I can read the message normally, but... when I click in "reply" instead of replying to the user that sent me the message, it replys to "me" (to contact#mywebsite.com).
I already configured the reply_to, to reply to users address, not mine, but still goes to contact#mywebsite.com.
How to fix this?
Should I change something more in the code or in gmail settings?
(PS.: I use gmail interface to read emails, directly from the site mail.google.com)
Thanks, in advance.
--
Also, when I receive the e-mail, It shows:
"From: 'Name in submitted form' "
Not:
"From: 'Name in submitted form' <'email in submitted form'>"
Like It should be.
Gmail does this, and I don't believe there is any sort of work around.
The "from" address will only ever be the account you are using to send the email - you cannot simply "pass through" gmail's server.
If you need to do that, you'll need something like SendGrid or your own smtp server
I fixed By sending the e-mail through another user ...
I sent from me#mywebsite.com to contact#mywebsite.com, and when I clicked in reply, the user selected was the same that sent the message in form.
GMail appearing to ignore Reply-To
Related
I am trying to send a registration verification email to my new user via Gmail SMTP. user data is successfully saved to the database but email is not sent to the user email ID.
I am working on localhost
here is my code
$subject = "Please verify email for login";
$message = "
<p>Hi " . $this->input->post('hospital_name') . "</p>
<p>This is email verification mail from Codeigniter Login Register system. For complete registration process and login into system.
First you want to verify you email by click this <a href='" . base_url() . "register/verify_email/" . $verification_key . "'>link</a>.</p>
<p>Once you click this link your email will be verified and you can login into system.</p>
<p>Thanks,</p>
";
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'tls://smtp.googlemail.com',
'smtp_port' => 587,
'smtp_user' => '****',
'smtp_pass' => '****',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('****');
$this->email->to($this->input->post('hospital_email'));
$this->email->subject($subject);
$this->email->message($message);
if ($this->email->send()) {
$this->session->set_flashdata('message', 'Check in your email for email verification mail');
redirect('register');
}else{
$this->session->set_flashdata('message', 'something wrong');
}
There could be a possibility that there might be something wrong with the code and it would be throwing some error. Did you check in the session, what is the message you're receiving?
If there's an error, try checking what the error could possibly be. You may check the error by using the below code.
if($this->email->send()) {
echo 'Your Email has successfully been sent.';
}
else{
show_error($this->email->print_debugger());
}
Error screentshot Hello guyz i am doing sending mail function in codeingniter, Same email function working in localhost but it did not work in live server i cant understand this error please help me..
This is my Email code:
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'email', // change it to yours
'smtp_pass' => 'password', // change it to yours
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$message = "
<html>
<head>
<title>Verification Code</title>
</head>
<body>
<h2>Thank you for Registering.</h2>
<p>Your Account:</p>
<p>Dear: ".$firstname."</p>
<p>Please click the link below to activate your account.</p>
<h4><a href='".base_url()."welcome/activate/".$id."/".$code."'>Activate My Account</a></h4>
</body>
</html>
";
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from($config['smtp_user']);
$this->email->to($email);
$this->email->subject('Signup Verification Email');
$this->email->message($message);
//sending email
if($this->email->send()){
$this->session->set_flashdata('message','Register Successfull And your Activation link send in Email Please Verify Your Account');
}
else{
$this->session->set_flashdata('message', $this->email->print_debugger());
}
ERROR:
Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.
The error you are showing is not related to your code rather its authentication error mean google servers are not allowing you to sign in.
Now in order to run this code, make sure you are using the right username and password.
After that, you have to turn on "Allow less secure apps" option from your Google/Gmail account.
After that, your code should be able to send an email.
Also, When you have uploaded your script into web host then you should use the email address of your domain name, like support#yourDomain.com it looks more professional.
Given below code is fully working code. Before you run it you must create an email address like admin#yourDomain.com from your hosting panel where there will be an option of email management.
$this->load->library('email');
$encodeEmail = bin2hex('email#gmail.com']);
$this->email->from('admin#yourDomain.com', 'Your Domain');
$this->email->to('email#gmail.com');
$this->email->subject('Email Verification Required');
$url = site_url() . 'verify/' . $data['verification'] . '/' . $encodeEmail;
$message = "";
$message .= "You have signed up with our website \r\n";
$message .= "Please click on given below link to verify and activitate your account. \r\n" . $url;
$this->email->message($message);
$this->email->send();
I am working on making newsletters. I have bulk of 1200 emails but it's not verified. I am using google mail smtp for verification in codeigniter framework. Mail is properly sending but when I tested it for wrong email then also it shows send mail status. I want to ask that how to get the response of bounced mail when working with google mail smtp.
$check is containing array of emails :
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => '465',
'smtp_user' => 'mymail#gmail.com',
'smtp_pass' => 'mypass',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'send_multipart' => FALSE
);
$this->email->initialize($config);
$this->load->library('email', $config);
foreach($_POST['chk'] as $check)
{
$this->email->clear();
$data = array(
'userName'=> 'Myname'
);
$this->email->set_newline("\r\n");
$this->load->library('email',$config);
$this->email->from("mymail#gmail.com","Myname");
//echo $row->email;
$this->email->to($check);
$this->email->subject("THIS IS AN EMAIL TEST");
$gett = $this->load->view('home_test.php',$data,TRUE);
$this->email->message($gett);
$this->email->set_mailtype("html");
if($this->email->send())
{
echo "Your Mail send";
}
else
{
show_error($this->email->print_debugger());
exit();
}
}
Its always showing Your Mail send although if I provide fake email id. How to track this bounced mail in PHP.
You will not get status of the bounced emails immediately after sent. What you can do is, specify return path email as third parameter of $this->email->from("mymail#gmail.com","Myname");.
Change this line
$this->email->from("mymail#gmail.com","Myname");
to
$this->email->from("mymail#gmail.com","Myname", 'yourreturnemail#gmail.com');
For more details see codigniter's email documentation here
This way all bounced emails will come to the return path email address. Then you can create a cron or something to read and parse this emails. php's imap extension can be installed and use for read email bounced status.
Good morning,
I want to remove the gmail warning 'gmail couln't verify that ...#... sent this message' when I send email with php.
I know it is because I use the email function php that don't have authentification so I try PHPMailer and PHP pear but the page turn and turn until the infinite and nothing is happened.
My host is 1&1.
I try with gmail instead smtp and account instead of 1&1 but same result.
<?php
// Pear Mail Library
require_once "Mail.php";
$from = '<***#motelavigna.co>'; //change this to your email address
$to = '<***#gmail.com>'; // change to address
$subject = 'Insert subject here'; // subject of mail
$body = "Hello world! this is the content of the email"; //content of mail
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$smtp = Mail::factory('smtp', array(
'host' => 'auth.smtp.1and1.fr',
'port' => '465',
'auth' => true,
'username' => '***#***.co', //co is not an error
'password' => '***' // your password
));
// Send the mail
$mail = $smtp->send($to, $headers, $body);
?>
thanks.
I came across this issue recently too and realised the problem is not from the PHP script, as I first thought, but from not having an SPF record for the domain name.
An SPF record identifies which mail servers are permitted to send emails from a particular domain name. If the domain doesn't have an SPF record then Gmail can't verify that the email came from the right place.
Coincidentally I'm also with 1&1, so see here for how to set up SPF records for 1&1. The value you need to use is:
v=spf1 include:_spf.perfora.net include:_spf.kundenserver.de -all
You can also check if the email passed the SPF test by clicking the arrow at the top of the email in Gmail, and pressing 'Show original'.
I am trying to send email in Yii using PHPMailer. I am working on a live server. Here is my Configuration for email in Yii's main.php:
'Smtpmail' => array(
'class' => 'application.extensions.smtpmail.PHPMailer',
'Mailer' => 'smtp',
'SMTPAuth' => true,
),
Here is the error I get:
The following From address failed: noreply#mywebsite.com : Called
Mail() without being connected
Here is my controller Code:
$mail->IsHTML(true);
$mail->From = Yii::app()->params['adminEmail'];
$mail->FromName = empty($_POST['EmailForm']["from_name"])
Yii::app()->params['emailFrom'] : $_POST['EmailForm']["from_name"];
$mail->Subject = $subject;
$mail->Body = nl2br($message) . $mail->Body;
$mail->AddAddress($to);
$mail->AddCC($cc);
if (!$mail->Send()) {
Yii::app()->user->setFlash('error', $mail->ErrorInfo);
$this->redirect(array('update', 'id' => $id));
}
else {
Yii::app()->user->setFlash('success', "Email sent successfully!");
$this->redirect(array('update', 'id' => $id));
}
Any help?
You're enabling auth but not providing an id or password, which doesn't seem likely to work. You're also setting the submitter's address as the from address, which is also likely to fail as it's a forgery that will fail SPF checks. Set your own address as the from address and put the submitter in a reply-to.
Beyond that, enable debug output (SMTPDebug = 2 in PHPMailer - I'm not sure how you set that from Yii) so you can see the SMTP conversation.