Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
need email from PHP scripts [SOLVED]
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
veilig
Apprentice
Apprentice


Joined: 11 May 2005
Posts: 153

PostPosted: Mon Jan 19, 2009 5:40 pm    Post subject: need email from PHP scripts [SOLVED] Reply with quote

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
View user's profile Send private message
nurachi
Tux's lil' helper
Tux's lil' helper


Joined: 16 May 2008
Posts: 92
Location: Paris

PostPosted: Mon Jan 19, 2009 6:13 pm    Post subject: Reply with quote

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
View user's profile Send private message
veilig
Apprentice
Apprentice


Joined: 11 May 2005
Posts: 153

PostPosted: Mon Jan 19, 2009 7:01 pm    Post subject: Reply with quote

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
Code:
No mail for root


what do I have to change to remedy this?
Back to top
View user's profile Send private message
nurachi
Tux's lil' helper
Tux's lil' helper


Joined: 16 May 2008
Posts: 92
Location: Paris

PostPosted: Mon Jan 19, 2009 7:44 pm    Post subject: Reply with quote

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
View user's profile Send private message
veilig
Apprentice
Apprentice


Joined: 11 May 2005
Posts: 153

PostPosted: Mon Jan 19, 2009 7:55 pm    Post subject: Reply with quote

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
View user's profile Send private message
nurachi
Tux's lil' helper
Tux's lil' helper


Joined: 16 May 2008
Posts: 92
Location: Paris

PostPosted: Mon Jan 19, 2009 8:34 pm    Post subject: Reply with quote

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
View user's profile Send private message
veilig
Apprentice
Apprentice


Joined: 11 May 2005
Posts: 153

PostPosted: Mon Jan 19, 2009 8:56 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum