I'm working with Codeigniter in CPanel and my code already sends a mail, but when it gets to the receiver, the hostname is shown on the sender.
I tried some answer to questions as : Change the sender name php mail instead of sitename#hostname.com but in Codeigniter, they don't work.
This is my code:
$config = Array(
'protocol' => 'ssmtp',
'smtp_host' => 'ssl://ssmtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'mail#domainiwant.com',
'smtp_pass' => 'password',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'useragent' => 'MY NAME',
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('mail#domainiwant.com', 'MY NAME');
$email_to = 'receiver#gmail.com';
$this->email->to($email_to);
$this->email->message('Message testing ...');
$this->email->send();
However, as I said, when the mail gets to the receiver, they appear with the hostname and a completely different mail address like the one I put on $config
I know this only sets the envelope sender but I want to set the mail address to be mail#domainiwant.com instead of receiving the mail with somemail#host.com.ex
According to the documentation of CodeIgniter's email library available HERE, your whole problem is a simple typo.
$config['protocol'] allows mail, sendmail and smtp as values. If you don't set the variable, or use a value which is not allowed, the whole library defaults to mail which attempts to use your own server as the mail gateway (which explains why your sender address shows as username#servername)
Change the protocol from ssmtp to smtp so that you actually use the Google SMTP server you intend to use and you'll get the results you expect
Related
I tried to send a email to a Gmail account (both receiver and sender accounts were created by me and both allow access to less secured apps) via CodeIgniter, using the following settings (from my localhost WAMP sever):
$config['smtp_user']='my gmail address';
$config['smtp_pass']='my password';
$config['smtp_port']=465;
$config['smtp_host']='ssl://smtp.googlemail.com';
$config['charset']='utf-8';
$config['protocol'] ='smtp';
The code snippet looks like this :
$this->email->from(my gmail address... , 'admin');
$this->email->to($reciever_email);
$this->email->subject(...);
$this->email->message(...);
$this->email->send();
But the mail does not get send (No weird error messages like fatal error etc. is displayed only the custom message I decided to show on failure is shown).
Can any one tell me why and how to get rid of this problem.
Try this instead:
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => '465',
'smtp_user' => 'my user',
'smtp_pass' => 'my password',
'smtp_charset' => 'utf-8'
);
I'm trying to send email using codeIgniter's email library.
Below is my code
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.myserver.com',
'smtp_user' => 'xxx#myserver.com',
'smtp_pass' => '********',
'mailtype' => 'html',
'wordwrap' => false,
'charset' => 'utf-8'
);
$this->email->initialize($config);
$this->email->set_newline("\r\n");
$this->email->from('xxx#yourserver.com', 'xxx');
$this->email->subject('blah blah');
$this->email->message('a simple html message');
$this->email->to('any#validemail.com');
$this->email->send();
Code is on diffrent server & it is using different server's mail (Yes, two different domains)
For example code is on yourserver.com and it is using smtp of myserver.com
It was working fine till morning. but now i'm getting
554 SMTP synchronisation error (see attachment for full print_debugger() output, I hide some sensitive information. i can trust you guys but not all)
Thanks.
I tried very hard to get the issue, but i have not enough access to get details of error log or mail logs, So i changed my code as below and it worked
$config = Array(
'mailtype' => 'html',
'wordwrap' => false,
'charset' => 'utf-8'
);
$this->email->initialize($config);
$this->email->set_newline("\r\n");
$this->email->from('xxx#yourserver.com', 'xxx');
$this->email->subject('blah blah');
$this->email->message('a simple html message');
$this->email->to('any#validemail.com');
$this->email->send();
I would like to say thanks to #cherrysoft for his help offering. I'm posting it here so it may help someone.
thanks to all.
This isn't really a CodeIgniter problem and there could be quite a few things going on here but the first thing I would do is to make sure that the hostname on the web server is set correctly and that your mail server recognises this host. You should tail the mail.log on your mail server (if you have access to do this) whilst you are sending mail from your web server and you will get some more insight as to what is going on. When you have the mail log entries post here and we can look at the issue in more depth.
I am using this extension.
http://www.yiiframework.com/extension/smtp-mail
I would work properly. But From Email id in mail not set that i have defined in "SetFrom()" function but it takes Gmail username (myemail#gmail.com).
Below is my code for sending mail in my Controller.
$mail = Yii::app()->Smtpmail;
$mail->SetFrom("otherid",$from_name); // This id not coming in my response mail
$mail->Subject = $subject;
$mail->MsgHTML($message);
$mail->AddAddress($to, "");
config/main.php
'Smtpmail'=>array(
'class' => 'application.extensions.smtpmail.PHPMailer',
'Host' => "smtp.gmail.com",
'Username' => 'myemail#gmail.com',
'Password' => 'password',
'Mailer' => 'smtp',
'Port' => 465,
'SMTPAuth' => true,
'SMTPSecure' => 'ssl'
),
Gmail doesn't seem to allow sending the email via a different email-id if its not registered to the primary gmail account.
When logged in to the primary gmail account -> go to Account tab (top-right).
Search for Add another email address under Send mail as.
Add the new email address there. Confirm the link sent to the additional email account.
On confirmation, your account can send emails from either of the address.
Try the new email address now in $mail->SetFrom("new_gmail_id#gmail.com", $from_name); and it will work fine.
I have tried that and it works. Let us know if you have done all this already.
I have the following code which sets up the SMTP server:
ini_set("send_from", "test#gmail.com");
ini_set("SMTP", "smtp.gmail.com");
and i create a simple mail in this way:
mail("test#yahoo.com", "A subject", "My message for you", "From: TEST");
When I run this code, it fails to send mail to Yahoo e.g. some.email#yahoo.com. But when i use any Gmail mail address as the first argument, it works.
What's wrong ?
To send mail as an authenticated user you should use email authentication methods like SPF, DKIM etc.
Also you need to make sure your domain should point to your IP address and IP address MUST point to same domain. This is called Reverse DNS
Other good practice that prevents mails from going into spam folder are
Make sure you have a unsubscribe link
Make sure the Reply-To header is added and the email used here is a valid email.
Add a Name in the To field. Like First Last <email#example.com>
Add a postal address of the company you are mailing from which must include a phone number.
There was a form to white list email senders IP for yahoo. Now I dont find it. So try the above things, It should work well.
In thi case you dont auth (user name passwort) and dont usw tls. This wont be accepted.
Better use this:
XAMPP Sendmail using Gmail account
or an framework to send emails via smtp like
Zend Mail Gmail SMTP
http://framework.zend.com/manual/1.12/en/zend.mail.sending.html
Here a code example
http://framework.zend.com/downloads/latest#ZF1
require('Zend/Mail.php');
$config = array(
'ssl' => 'tls',
'port' => 587,
'auth' => 'login',
'username' => 'your_gmail_address#gmail.com',
'password' => 'password'
);
$smtpConnection = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
Zend_Mail::setDefaultTransport($smtpConnection);
Zend_Mail::setDefaultFrom('your_gmail_address#gmail.com', 'Your real name');
$mail = new Zend_Mail();
$mail->addTo('any_address#yahoo.com', 'Test');
$mail->setSubject(
'Demonstration - Sending Mails per SMTP Connection'
);
$mail->setBodyText('...Your message here...');
$mail->send($smtpConnection);
Well I'm trying to send a HTML email using gmail smtp from CI, and it seems to reject my emails when they have any amount of tables. No error is given, they just do not appear in my inbox.
If I send an email with light HTML and no tables, they go through. Anyone have any insight?
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => '------#gmail.com',
'smtp_pass' => '--------',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('myEmail', 'myName');
$this->email->to($this->input->post('email'));
$this->email->subject('mySubject');
$msg = $this->load->view('partials/email', '', true);
$this->email->message($msg);
$this->email->send();`
Using PHP double quotes evaluate variables and control characters (e.g. \n or \r), whereas single quotes do not. Also open the way to different interpretation = (equal sign).
It not using TABLE is generation problem it is any tag with parameter ="value".
Make sure you have right string in single quotes, test this on basic A tag
The content of view 'partial/email' is the key
Include also the text/plain version of the message. Maybe it will go through, if you say that light html works