View previous topic :: View next topic |
Author |
Message |
veilig Apprentice
Joined: 11 May 2005 Posts: 153
|
Posted: Mon Jan 19, 2009 5:40 pm Post subject: need email from PHP scripts [SOLVED] |
|
|
I have a web server setup on my machine w/ php and need to send some simple emails from PHP scripts. not worried about replies just need them to go out.
what will be the easiest / fastest (to setup) program to use for this? and where can I find some tutorials on how to do it?
thanks!
Last edited by veilig on Mon Jan 19, 2009 8:57 pm; edited 1 time in total |
|
Back to top |
|
|
nurachi Tux's lil' helper
Joined: 16 May 2008 Posts: 92 Location: Paris
|
Posted: Mon Jan 19, 2009 6:13 pm Post subject: |
|
|
1. Simply install mail-mta/ssmtp configured with your ISP SMTP relay server.
2. Take care that the /usr/bin/sendmail symbolic link exists and/or that your php.ini mail settings are correct.
3. Then, you could use the PHP mail() function. |
|
Back to top |
|
|
veilig Apprentice
Joined: 11 May 2005 Posts: 153
|
Posted: Mon Jan 19, 2009 7:01 pm Post subject: |
|
|
ok, think I'm almost there, just have a quick snag (hopefully)
I emerged ssmtp and followed this guide
http://www.destr0yr.com/article.php/Gmail_and_sSMTP
I can run his test and get an email successfully, I can also
Code: | ssmtp recipient_email@example.com |
and get an email successfully.
I have a sym-link for /usr/bin/sendmail and /usr/sbin/sendmail, both go to /usr/sbin/ssmtp
and in my
/etc/php/apache2-php5/php.ini
sendmail_path="/usr/sbin/sendmail"
BUT when I try the mail command in a PHP script it fails, and when I check my /var/logs/apache2/error_log I have an entry of
what do I have to change to remedy this? |
|
Back to top |
|
|
nurachi Tux's lil' helper
Joined: 16 May 2008 Posts: 92 Location: Paris
|
Posted: Mon Jan 19, 2009 7:44 pm Post subject: |
|
|
Change
sendmail_path = /usr/sbin/ssmtp -t
Try to change:
Code: | sendmail_path="/usr/sbin/sendmail" |
to
Code: | sendmail_path = /usr/sbin/ssmtp -t | (sorry).
Or:
Code: | su apache
ssmtp recipient_email@example.com |
If it works, the problem is in your mail( ) function call.
If you don't provide all necessary informations, PHP'll use default settings (http://www.php.net/manual/en/mail.configuration.php).
You can't find ssmtp logs in /var/log/mail.log |
|
Back to top |
|
|
veilig Apprentice
Joined: 11 May 2005 Posts: 153
|
Posted: Mon Jan 19, 2009 7:55 pm Post subject: |
|
|
I changed my sendmail_path but the mail command doesn't even return a boolean true result now.
and when I check my apache error_log I have these in there
ssmtp: Cannont open mailhub:25
my mailhub in my /etc/ssmtp/ssmtp.conf file is as it should be:
Code: |
mailhub=smtp.gmail.com:587 |
seems I must still be missing something |
|
Back to top |
|
|
nurachi Tux's lil' helper
Joined: 16 May 2008 Posts: 92 Location: Paris
|
Posted: Mon Jan 19, 2009 8:34 pm Post subject: |
|
|
mail() returns a boolean otherwise that means it crashed.
Set error_reporting like this in your PHP ini
Code: | error_reporting = E_ALL |
Be sure you're not dropping exceptions somewhere in your code.
And this (again)?
Code: | su apache
ssmtp recipient_email@example.com |
What does this do?
Code: | <?php
$to = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?> |
|
|
Back to top |
|
|
veilig Apprentice
Joined: 11 May 2005 Posts: 153
|
Posted: Mon Jan 19, 2009 8:56 pm Post subject: |
|
|
I read a couple of the bug reports for smtp and changed the ssmtp.conf file permissions and was able to get everything running.
Thanks so much for your help! |
|
Back to top |
|
|
|