Fedora 10 Server: Sending emails with php scripts

Discussion in 'Server Operation' started by bryand1, Jul 21, 2009.

  1. bryand1

    bryand1 New Member

    Hello,

    What do I need to enable on my fedora 10 server so that I can send emails with a simple PHP mail script?

    I have already opened PORT 25.

    Thank you,

    Bryan Andrade
     
  2. falko

    falko Super Moderator Howtoforge Staff

    PHP's mail() function should work out of the box.
     
  3. tom.hill

    tom.hill New Member

    Hi bryand1,

    I'm also having the same problem on CentOS 5.3 x64

    I think we must be missing something?

    Tom
     
  4. tom.hill

    tom.hill New Member

    I wonder if anyone can help?

    I have created a test page with the following code:
    Code:
    <?php
    function send_email($from, $to, $cc, $bcc, $subject, $message){
    	$headers = "From: ".$from."\r\n";
    	$headers .= "Reply-To: ".$from."\r\n";
    	$headers .= "Return-Path: ".$from."\r\n";
    	$headers .= "CC: ".$cc."\r\n";
    	$headers .= "BCC: ".$to."\r\n";
    	
    	if (mail($to,$subject,$message,$headers) ) {
    	   echo "email sent";
    	} else {
    	   echo "email could not be sent";
    	}
    }
    
    $subject = "Hello!";
    $message = "Hello! How are you today?";
    send_email("[email protected]", "[email protected]", 
    	"[email protected]", "[email protected]",
    	$subject , 
    	$message);
    ?>
    When I view the page above I get 'email sent' but no mail is received. If I run the command
    Code:
    postsuper -d ALL
    I get
    so it looks to me like the messages are going into the queue? Do I have to specify my ISP's smtp relay server anywhere in the postfix config?

    Kind regards,

    Tom


    Edit, also if I view the mail queue on Ispconfig 3 after running the test script above it shows:

    Data from: 2009-07-29 16:15
    /var/spool/mqueue is empty
    Total requests: 0

    Is this a different queue?
     
    Last edited: Jul 29, 2009
  5. av1611

    av1611 New Member

    I found that PHP does not work out of the box with sendmail on F10 so I got around the problem by just install postfix which took all of 10 minutes and is much easier to use anyway.

    I know that's not the answer you was looking for but that's what I came up with last year when I had the same problem.
     
  6. av1611

    av1611 New Member

  7. tom.hill

    tom.hill New Member

    Thanks AV,

    I managed to install postfix fairly easily (yum erase sendmail, yum install postfix) and start it but my emails via my test page are still not getting through.

    I'm not sure what or how to test? :(

    Tom

    Edit:

    If I try to send a test email from the command line using:

    echo "test" | mail -s testsubject [email protected]

    The email doesn't get through but defiantly joins a queue:

    [root@rnetweb1 /]# postsuper -d ALL
    postsuper: Deleted: 1 message
     
    Last edited: Aug 3, 2009
  8. av1611

    av1611 New Member

    Try running the session in telnet:
    howto:
    http://tranquilpenguin.com/wordpress/?p=57

    follow the example exactly and see if you get some errors. Are you on a public network? does you ISP allow you to send port 25? This is a good way to find out.
     
  9. tom.hill

    tom.hill New Member

    Thanks AV,

    Sorry about the delay, I took a long needed holiday!

    I have tried to telnet to the box from an XP machine and also to telnet to the box locally from the box itself.

    from a local WinXP machine:
    telnet 10.101.1.50 25

    command prompt goes blank

    from the box itself:
    telnet 10.101.1.50 25 (or telnet localhost 25)

    Trying 10.101.1.50...
    Connected to host1.domain.local (10.101.1.50).
    Escape character is '^]'.

    and then no command has any effect (I actually have to reboot the server using XenCentre because I can't get out of the telnet prompt!)

    I can telnet to my Exchange server just fine.

    This must highlight a big problem somewhere, just wish I knew what it was!

    :(

    Tom
     
  10. falko

    falko Super Moderator Howtoforge Staff

    Are there any errors in your mail log?
     
  11. tom.hill

    tom.hill New Member

    Thanks for your reply Falko, I don't suppose you know an easy way to view the log? :S

    Kind regards,

    Tom
     
  12. falko

    falko Super Moderator Howtoforge Staff

    To display the last 500 lines:
    Code:
    tail -n500 /var/log/mail.log
    You can also use a text editor such as vi to open the log:
    Code:
    vi /var/log/mail.log
     
  13. tom.hill

    tom.hill New Member

    Thanks Falko,

    Sorry I'm having a bit of difficulty using Linux in my virtual environment, I noticed that I have the following log files though:

    maillog.1
    maillog.2
    maillog.3
    maillog.4

    and the directory 'mail' containing only statistics.rpmsave

    I managed to copy and paste only a screens worth of output from the command:

    tail -n500 /var/log/maillog

    xymap: bad command startup -- throttling
    Aug 21 16:02:27 rnetweb1 postfix/smtpd[13897]: fatal: unsupported dictionary type: mysql
    Aug 21 16:02:27 rnetweb1 postfix/qmgr[13898]: fatal: unsupported dictionary type: mysql
    Aug 21 16:02:28 rnetweb1 postfix/master[1815]: warning: process /usr/libexec/postfix/qmgr pid 13898 exit status 1
    Aug 21 16:02:28 rnetweb1 postfix/master[1815]: warning: /usr/libexec/postfix/qmgr: bad command startup -- throttling
    Aug 21 16:02:28 rnetweb1 postfix/proxymap[13899]: fatal: unsupported dictionary type: mysql
    Aug 21 16:02:28 rnetweb1 postfix/master[1815]: warning: process /usr/libexec/postfix/smtpd pid 13897 exit status 1
    Aug 21 16:02:28 rnetweb1 postfix/master[1815]: warning: /usr/libexec/postfix/smtpd: bad command startup -- throttling
    Aug 21 16:02:29 rnetweb1 postfix/cleanup[1852]: warning: premature end-of-input on private/proxymap socket while reading input attribute name
    Aug 21 16:02:29 rnetweb1 postfix/cleanup[1852]: warning: private/proxymap socket: service dict_proxy_open: Success
    Aug 21 16:02:29 rnetweb1 postfix/master[1815]: warning: process /usr/libexec/postfix/proxymap pid 13899 exit status 1
    Aug 21 16:02:29 rnetweb1 postfix/master[1815]: warning: /usr/libexec/postfix/proxymap: bad command startup -- throttling

    And I have to say, although I'm not very sure about what it means, it doesn't look like good news!

    Thanks very much for your help this far guys.

    Kind regards,

    Tom
     
  14. falko

    falko Super Moderator Howtoforge Staff

    This means that your Postfix doesn't have MySQL support. What guide did you use to set up your system? Did you update your system since you used the guide?
     
  15. tom.hill

    tom.hill New Member

    I used your guide Falko:

    http://www.howtoforge.com/perfect-server-centos-5.3-x86_64-ispconfig-3

    I might have run a 'yum update' command after finishing the guide, could this have caused the issues?

    Also since following that guide I have changed Sendmail for Postfix to try and solve the issue without any success as of yet.

    Do I need to reinstall/fix MySQL or something like that?

    Kind regards,

    Tom
     
  16. falko

    falko Super Moderator Howtoforge Staff

    Yes, this has probably wiped Postfix' MySQL support. You need to redo the appropriate steps from the tutorial.

    In the guide I install Postfix, not Sendmail...
     
  17. tom.hill

    tom.hill New Member

    Thanks Falko,

    I might actually start again from scratch.

    So you would warn against from running 'yum update' on this setup ever?

    Kind regards,

    Tom
     
  18. falko

    falko Super Moderator Howtoforge Staff

    Yes, or at least make sure that Postfix doesn't get updated.
     
  19. tom.hill

    tom.hill New Member

    New server up, running and working, thank you for your help Falko, great howto's just a lack of Linux knowledge on my side causing the issues!

    Kind regards,

    Tom
     

Share This Page