I've recently installed my server on VPS, PHP mail is not working, I've tryed everywhere but I can't get it to work. If it is not a syntax error I would appreciate if someone could help with setting PHP mail up. Im running ubuntu 10.04
My code is:
$ToEmail = 'my#email.com';
$EmailSubject = 'Site contact form ';
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$_POST["name"]."<br>";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>";
$MESSAGE_BODY .= "Message: ".nl2br($_POST["message"])."<br>";
$MESSAGE_BODY .= "IP: ".$_SERVER['REMOTE_ADDR']";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
According to the log you posted:
Jun 13 11:49:42 hedgehog postfix/master[12617]: fatal: bind 0.0.0.0 port 25: Address already in use
This should give you a clue if you are unable to connect to your server.
Related
I'm trying to write a script to update my database after the payment of the customer. My problem is that after the call of curl_init nothing seems to be happening...
My code is:
$pp_url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
$ch = curl_init($pp_url);
As nothing was happening, I added some debug code in my log file, like that:
if ($ch === false) {
addLog("Curl_init returned false");
}
else {
addLog("Curl_init worked ok");
}
Problem: no message is displayed in my log file.
I receive the log file content until these lines and then nothing.
Is there a way to understand what's going on ?
Because now I'm stuck, as I don't receive anything from Paypal...
So I'm not able to test weither or not the transaction went ok.
Please, I really need some help.
Thanks
How your addLog function is working?
You may try something that look like this:
// post back to PayPal system to validate
$header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Host: www.paypal.com\r\n";
$header .= "Connection: close\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
change the paypal.com adress to the sandbox one.
I never tried with curl, but it does work with fsockopen.
I'm trying to send a raw email with image attachments via AmazonSES using PHP. It works great when I send the email to a gmail account but hotmail accounts are receiving empty attached images. In other words, hotmail seems to recognize that there are attachments and these attachments have the correct name that i specified, it's just that they are always empty, sized 0 bytes. Googling is not helping... Thanks in advance!
$amazonSES = new AmazonSES();
// if (empty($attach)==0) {
// $response = $amazonSES->send_email(AWS_SES_FROM_EMAIL,
// array('ToAddresses' => array($to)),
// array('Subject.Data' => $subject,'Body.Text.Data' => $messagein,)
// );
// } else {
$rstring = 'ajfas90lsjhntlen89y34oi598';
$message= "To: ".$to."\n";
$message.= "From: " . AWS_SES_FROM_EMAIL . "\n";
$message.= "Subject: " . $subject . "\n";
$message.= "MIME-Version: 1.0\n";
$message.= 'Content-Type: multipart/mixed; boundary="ARandomString'.$rstring.'"';
$message.= "\n\n";
$message.= "--ARandomString$rstring\n";
$message.= 'Content-Type: text/plain; charset="utf-8"';
$message.= "\n";
$message.= "Content-Transfer-Encoding: 7bit\n";
$message.= "Content-Disposition: inline\n";
$message.= "\n";
$message.= $messagein;
$message.= "\n\n";
$message.= "--ARandomString$rstring\n";
foreach ($attach as $attachment) {
// $message.= "Content-ID: \<77987_SOME_WEIRD_TOKEN_BUT_UNIQUE_SO_SOMETIMES_A_#domain.com_IS_ADDED\>\n";
$message.= "Content-ID: \<". md5(uniqid(rand(), true)) ."#biomechanico.com\>\n";
$message.= 'Content-Type: application/zip; name="shell.zip"';
$message.= "\n";
$message.= "Content-Transfer-Encoding: base64\n";
$message.= 'Content-Disposition: attachment; filename="' . $attachment["name"] . '"';
$message.= "\n" . base64_encode(file_get_contents($attachment["file"])) . "\n";
$message.= "--ARandomString$rstring\n";
}
$response = $amazonSES->send_raw_email(array(
'Data'=> base64_encode($message)),
array('Source'=>AWS_SES_FROM_EMAIL, 'Destinations'=> $to));
You are producing a malformed message.
Consider using a proper library for generating mail messages, instead of stitching them together from raw strings.
Otherwise, here’s what I notice right away.
The final multipart boundary must be terminated by an extra --, i.e. the last line must be:
--ARandomStringajfas90lsjhntlen89y34oi598--
rather than
--ARandomStringajfas90lsjhntlen89y34oi598
In the attachment parts, you do not have a blank line between the Content-Disposition header line and the body.
Message lines must not be longer than 998 characters, but your Base64-encoded attachment data, however long, is always on a single line.
As far as I understand PHP, your syntax for Content-ID in the attachment parts is wrong, in that it produces Content-ID: \<whatever\> but should produce Content-ID: <whatever>
Lines must be terminated by CR LF (\r\n), but you have LF (\n).
A good way to debug message problems is to take the actual full generated message source ($message) and run it through Message Lint. If the above suggestions do not help, please post the generated message source rather than the PHP code.
For the Internet message format, please refer to RFC 5322. For the multipart message syntax, please refer to RFC 2046.
I'm working on a Zend project in a very specific server configuration, our production environment is made of two dedicated servers, one for the company's email which host a postfix server and an other server for our web-application which is running on Apache2/Zend.
Those servers have two different IPs, but works on the same website domain.
Now when i try to send an email with an email from the mail server as a sender, i get an error 500 from Zend_Mail and the email.err log tells me :
postfix/sendmail[15782]: fatal: -n option not supported
But when i put a local adresse or a blank email as a sender it works, so i guess i get kicked out by the postfix of the webserver because it doesn't manage localy those emails.
So my question is: is there any way to use a domain email as sender from a distant server without merging the two servers?
Edit: i forgot to add: i can't use the distant server SMTP, i only can use a local sendmail.
I haven't find any solution or explanations so i ended up by writing a custom action helper based on the mail command of PHP.
I hope it can help someone:
class Zend_Controller_Action_SentEmail extends Zend_Controller_Action_Helper_Abstract{
public function sendEmail($from, array $to, $subject, $message){
//Header set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= "From: ".$from."<email#domain.com>\r\n";
$headers .= "X-Mailer: PHP/".phpversion();
//To
$stringTo = "";
foreach($to as $k => $v) {
$stringTo .= $k." <".$v.">, ";
}
$stringTo = trim($stringTo, ", ");
//Send the email
if(mail($stringTo, $subject, $message, $headers, "-f bounce#domain.com")){
return true;
}
else{
//Oh! Noes!
return false;
}
}
}
I have written a perl script to send email using the gmail's smtp server: smtp.gmail.com -
use Net::SMTP;
my $smtp = Net::SMTP->new('smtp.gmail.com',
Port=> 587,
Timeout => 20,
Hello=>'user#gmail.com'
);
print $smtp->domain,"\n";
$sender = "user#gmail.com";
$password = "mypassword";
$smtp->auth ( $sender, $password ) or die "could not authenticate\n";
$receiver = "user#gmail.com";
$subject = "my custom subject";
$smtp->mail($sender);
$smtp->to($receiver);
$smtp->data();
$smtp->datasend("To: <$reciever> \n");
$smtp->datasend("From: <$sender> \n");
$smtp->datasend("Content-Type: text/html \n");
$smtp->datasend("Subject: $subject");
$smtp->datasend("\n");
$smtp->datasend('the body of the email');
$smtp->dataend();
$smtp->quit();
print "done\n\n";
For 'user', I have my gmail username and for 'mypassword' I have the password. But when I run this code it stops at the auth itself giving : could not authenticate.
I am able to connect to the smtp serever of google as I get : 'mx.google.com' as the result of :
print $smtp->domain,"\n";
What is it that I am doing wrong? Please help.
use Net::SMTP;
my $smtp = Net::SMTP->new ....
afaik you need to use an encrypted connection to send via gmail, use Net::SMTP::TLS or Net::SMTP::SSL (with port 465)
Hello=>'user#gmail.com'
'Hello' is not an email address, put your hostname there instead
$sender = "user#gmail.com";
...
$receiver = "user#gmail.com";
put these in single quotes
if you still get "could not authenticate." make sure you have the modules MIME::Base64 and Authen::SASL installed.
$smtp->datasend("To: <$reciever> \n");
should be $receiver, not $reciever
Gmail uses TLS/STARTTLS on port 587, SSL on port 465. Please follow Sending email through Google SMTP from Perl. Alternatively you could use Email::Send::SMTP::Gmail. I recommend this as it is way easier to use and has many more features.
I'm trying to send an e-mail with Codeigniter like this:
$this->load->library('email');
$this->email->from("myemail#email.com");
$this->email->reply_to("myemail#email.com");
$this->email->to("myemail#email.com");
$this->email->subject("Test mail");
$this->email->message("Email body");
$this->email->set_alt_message("Email body txt");
$this->email->send();
and I got this on the email debugger: Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.
If I do e simple PHP mail() function with the same addresses, it works but when I use CodeIgniter it gives me the error. So why would it work with simple mail() but not with CodeIgniter ? Any ideas ?
Thanks.
Had similar issue.
That's working code from the controller :
$config = array();
$config['useragent'] = "CodeIgniter";
$config['mailpath'] = "/usr/bin/sendmail"; // or "/usr/sbin/sendmail"
$config['protocol'] = "smtp";
$config['smtp_host'] = "localhost";
$config['smtp_port'] = "25";
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['wordwrap'] = TRUE;
$this->load->library('email');
$this->email->initialize($config);
$this->email->from($fromEmail, $fromName);
$this->email->to($email);
$this->email->subject('Тест Email');
$this->email->message($this->load->view('email/'.$type.'-html', $data, TRUE));
$this->email->send();
Clearly, there does not seem to be a definitive 'one size fits all' answer. What worked for me was changing
$config['protocol'] = 'smtp';
TO:
$config['protocol'] = 'mail';
Hope this helps...
Do you have an email.php file in your config folder? Maybe there's a problem with your configuration in there.
Nobody seemed to really find a definitive answer, so I did some digging around and found out why.
in system/libraries/Email.php, first look at line 1552:
if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, "-f ".$this->clean_email($this->_headers['From'])))
it seems to send everything all peachy like. I had the exact same symptoms too. To see if I was crazy, i inserted immediately before...
mail($this->_recipients, $this->_subject, $this->_finalbody)
so I basically removed all the headers and let PHP put in the defaults. Bingo! Without CI's headers, it works. With the CI headers, it doesn't. So what is it?
Digging around some more, I looked up to where html is initialized and used. Turns out it doesn't really do anything until around 1046, where it builds the message body.
from line 1048:
if ($this->send_multipart === FALSE)
{
$hdr .= "Content-Type: text/html; charset=" . $this->charset . $this->newline;
$hdr .= "Content-Transfer-Encoding: quoted-printable";
}
else
{
$hdr .= "Content-Type: multipart/alternative; boundary=\"" . $this->_alt_boundary . "\"" . $this->newline . $this->newline;
$body .= $this->_get_mime_message() . $this->newline . $this->newline;
$body .= "--" . $this->_alt_boundary . $this->newline;
$body .= "Content-Type: text/plain; charset=" . $this->charset . $this->newline;
$body .= "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline;
$body .= $this->_get_alt_message() . $this->newline . $this->newline . "--" . $this->_alt_boundary . $this->newline;
$body .= "Content-Type: text/html; charset=" . $this->charset . $this->newline;
$body .= "Content-Transfer-Encoding: quoted-printable" . $this->newline . $this->newline;
}
Flipping send_multipart between TRUE and FALSE will make the mail class work or not work.
Looked through the Code Ignitor's email class docs reveals nothing. Going to line 52:
var $send_multipart = TRUE; // TRUE/FALSE - Yahoo does not like multipart alternative, so this is an override. Set to FALSE for Yahoo.
So there you have it. Possibly an error in how CI does multipart messages? The hidden config preference
$config['send_multipart'] = FALSE;
in the email.php seems to do the trick.
Be sure domain name in
$this->email->from("myemail#**email.com**");
match to server domain name
Add a protocol variable to the config array and assign it the value "sendmail". The email.php file in the config folder should read as shown below. Mine works like this:
$config['protocol'] = 'sendmail';
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
Ensure that Apache can send emails.
To check your current sendmail status:
sestatus -b | grep httpd_can_sendmail
Change it to this if it is off:
sudo setsebool -P httpd_can_sendmail on
I read a comment in the file email.php :
// most documentation of sendmail using the "-f" flag lacks a space after it, however
// we've encountered servers that seem to require it to be in place.
return mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, '-f '.$this->clean_email($this->_headers['Return-Path']));
"-f" flag - this problem!!!
Had the same problem,
Make sure your 'from' address is a valid email address.
I had the same problem and though it seems silly to me now, I had some of the config array options capitalized when they all need to be lowercase:
was:
$mail_config['smtp_host'] = 'mail.example.com';
$mail_config['smtp_port'] = '587';
$mail_config['smtp_user'] = 'email#example.com';
$mail_config['smtp_pass'] = 'password';
$mail_config['smtp_crypto'] = 'TLS'; //ERROR
$mail_config['protocol'] = 'SMTP'; //ERROR
$mail_config['mailtype'] = 'HTML'; //ERROR
$mail_config['send_multipart'] = FALSE;
$this->email->initialize($mail_config);
Fixed:
$mail_config['smtp_host'] = 'mail.example.com';
$mail_config['smtp_port'] = '587';
$mail_config['smtp_user'] = 'email#example.com';
$mail_config['smtp_pass'] = 'password';
$mail_config['smtp_crypto'] = 'tls'; //FIXED
$mail_config['protocol'] = 'smtp'; //FIXED
$mail_config['mailtype'] = 'html'; //FIXED
$mail_config['send_multipart'] = FALSE;
$this->email->initialize($mail_config);
That worked for me
Its worth saying that if you're on WAMP (Windows) you will need to have sendmail installed otherwise there is no default SMTP method of sending. I wanted to use Gmail but couldn't because there is simply no default mail mechanism.
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'email',
'smtp_pass' => 'pass',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$this->load->library('email',$config);
**$this->email->set_newline("\r\n");** <- add this line
this code worked for me.