Php Mail sent with Postfix and phpmailer SOLVED!!!
Hi everyone,
I just want to post back specially to all of you who were real helpful in the process of getting this to work for me. I find it very complicated but it works now. Also before going on right now I feel that the mailserve for leapord is a rip off (probably cause I don't know how to use it) I bought it and ended up throwing it in the trash because I don't need it, it didn't even start postfix when I hit the postfix start icon. I still had to manually start postfix via terminal.
Anyhow, it's been a while and a long time since I started this thread so I don't know if I can cover every step to fix postfix to work with phpmailer as it was in my case on leopard. But here's my try.
this is the postfix main.cf configuration that worked for me:
confiugration that sends emails from Mac to Mac on Local envrionment or to outside emails.
# Minimum Postfix-specific configurations
mydomain_fallback = localhost
relayhost=smtp.gmail.com:587
mydomain=localhost
myhostname=localhost.com
# Enable SASL authentication in the Postfix SMTP client.
smtp_sasl_auth_enable=yes
smtp_sasl_password_maps=hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options=
# Enable Transport Layer Security (TLS), i.e. SSL.
smtp_use_tls=yes
smtp_tls_security_level=encrypt
tls_random_source=dev:/dev/urandom
inet_interfaces = all
inet_interfaces = $myhostname
#inet_interfaces = $myhostname, localhost
inet_interfaces = localhost
#sendmail_path = /usr/bin/mail
smtp_enforce_tls = yes
smtp_sasl_tls_security_options =
smtp_sasl_tls_verified_security_options =
smtp_tls_loglevel = 2
# optional if you wan to see what's going on with the TLS negotiation in /var/log/mail.log
smtp_sasl_password_maps = hash:/etc/postfix/smtp_sasl_passwords
smtp_tls_per_site = hash:/etc/postfix/smtp_tls_sites
tls_random_source = dev:/dev/urandom
mail_owner = _postfix
setgid_group = _postdrop
On the php.ini changing the sendmail path to mail -t -i or leaving it as the default didn't make a difference for me.
I also followed this tutorial:
http://blog.yuweijun.co.cc/2008/11/send-mail-through-gmail-smtp-using-php.html
but this is how I modified it for my local environment:
<?php
require_once("/usr/local/php5/PHPMailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->ContentType = "text/plain"; // text/plain or text/html
$mail->Host = "localhost"; // had been hacked in class.smtp.php, ssl://smtp.gmail.com
$mail->SMTPAuth = false;
$mail->Username = "rodrigo7x@localhost.com";
$mail->Password = "xxxxx";
$mail->From = "rodrigo7x@gmail.com";
$mail->FromName = "www.gmail.com";
$mail->AddAddress("rodrigo7x@gmail.com");
// CC and BCC
// $mail->AddCC("test@test.com");
// $mail->AddBCC("anothermail@test.com");
$mail->Subject = "This is my subject";
$mail->Body = "This is my message";
if(!$mail->Send()) {
echo "Message was not sent";
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Email sent";
}
?>
This site:
http://www.communitymx.com/content/article.cfm?page=2&cid=AF0CE
shows you how to modify the include path inside your php script incase you get this error I once got:
Warning: require_once(class.phpmailer.php) [function.require-once]: failed to open stream: No such file or directory in /Library/WebServer/Documents/mailer.php on line 3
Fatal error: require_once() [function.require]: Failed opening required 'class.phpmailer.php' (include_path='.:/usr/local/php5/lib/php') in /Library/WebServer/Documents/mailer.php on line 3
basically just put the path to the phpmailer class inside your php script!
Also, when you modify files like the postfix main.cf or php.ini make sure you do sudo postfix reload and sudo apachectl restart from the terminal for changes to take effect.
Also, I noticed that sometimes closing out the browser and reopening it fixes some things, I guess that's due to caching. I guess there's other ways to confiure postfix so that you can go directly to you isp for smtp but I found this that works. I had to read forums like this one to get my setup to work:
http://www.riverturn.com/blog/?p=239
cause you have to download a certificate to authenticate smtp. I remember I did a lot with that so you might have to google some more.
The other thing that I still don't understand is that although I can send emails now from php script and by telnet localhost 25 mail from: .. etc
I still cannot just type in terminal:
sh-3.2# date | mail -s test rodrigo7x@localhost.com
sh-3.2# mail: /usr/sbin/sendmail: No such file or directory
As you see somehow the machine thinks I want to use sendmail and according to some posts online postfix is suppose to have a link that executes any commands to sendmail towards postfix. But I guess it is not working for me. If any one has a fix for this, I appreciate it. Thank you.