23.12.2012 Posted September 5, 2009 Share Posted September 5, 2009 I was trying to use the PHP mail() function with additional headers (particularly From, Cc, Bcc), but it seems I've got something wrong, because the script fails to send the messages (it's not a mail server configuration error, because if I remove the additional headers, it works again). I'd also specify that I enter more than one address in the $to variable, but I think I'm doing it the right way: user1@domain1.tld, user2@domain2.tld, userN@domainN.tld. Any help here? $to = $_POST['to'];$subject = $_POST['subject'];$text = $_POST['text'];$cc = $_POST['cc'];$bcc = $_POST['bcc'];$header = 'From: Me <me5@domain.tld>' . '\r\n';$header .= 'Cc: ' . $cc . '\r\n';$header .= 'Bcc: ' . $bcc . '\r\n';// Code...mail($to, $subject, $text, $header); Link to comment Share on other sites More sharing options...
23.12.2012 Posted September 6, 2009 Author Share Posted September 6, 2009 Apparently, the problem was Gmail filtering my messages as Spam. Link to comment Share on other sites More sharing options...
Synook Posted September 6, 2009 Share Posted September 6, 2009 Yeah, to make it not spam you have to set the from domain to be the same domain that the SMTP server sits on. So if you said it comes from domain.com but your SMTP server is actually at example.com, many mail agents will consider that spam. Link to comment Share on other sites More sharing options...
23.12.2012 Posted September 6, 2009 Author Share Posted September 6, 2009 Now I'm trying to send using PEAR::Mail. I installed PEAR under htdocs. Everything seemed fine. Then I edited php.ini, and added the path of the PEAR implementation. Now that's how my php.ini looks, on a MAMP installation. ; For Unix only. You may supply arguments as well (default: "sendmail -t -i").sendmail_path = /usr/sbin/sendmail -t -i ; UNIX: "/path1:/path2" include_path = ".:/Applications/MAMP/bin/php5/lib/php:/Applications/MAMP/htdocs/PEAR" I don't know what else I need to do in order to get the SMTP authentication to work. Here's PEAR's sendmail.php, followed by smtp.php var $sendmail_path = '/usr/sbin/sendmail';var $sendmail_args = '-t -i'; var $host = 'smtp.gmail.com';var $port = 465;var $auth = true;var $username = 'my_gmail_address';var $password = 'my_gmail_password'; Last but not least, here's the part of the script which sends the mail include('/Applications/MAMP/htdocs/PEAR/Mail.php');$recipients = $to;$headers['MIME-Version'] = '1.0';$headers['Content-type'] = 'text/html; charset=iso-8859-1';$headers['From'] = 'my_gmail_address';$headers['To'] = $to;$headers['Subject'] = $subject;$headers['Cc'] = $cc;$headers['Bcc'] = $bcc;$body = $text;$params['sendmail_path'] = '/usr/sbin/sendmail -t -i';// Create the mail object using the Mail::factory method$mail_object =& Mail::factory('smtp', $params);$mail_object->send($recipients, $headers, $body);// Display a confirmation messageecho "The message has been successfully sent"; What am I doing wrong? Link to comment Share on other sites More sharing options...
Synook Posted September 7, 2009 Share Posted September 7, 2009 What happens? Link to comment Share on other sites More sharing options...
23.12.2012 Posted September 7, 2009 Author Share Posted September 7, 2009 I think it was crashing. Anyway, I got it working, I messed something up pretty badly Link to comment Share on other sites More sharing options...
justsomeguy Posted September 8, 2009 Share Posted September 8, 2009 Just for future reference, but a single-quoted string does not escape any characters other than a single quote. This string:'\r\n' will have those 4 characters in it. This string:"\r\n"will have a carriage return followed by a line feed. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.