Guest tezca Posted November 4, 2002 Report Share Posted November 4, 2002 I have a curious problem, I cannot send mail with php on "1" of my servers I can send mail when logged in, I can connect via pop, but I want to send mail from a form on a website to a mailbox not on my server I used the same code on another server and it works, I'm thinking it has to be in the php.ini file but I'm wondering if anybody can help me as to what I should look for? heres the code really simple <?php $PageTitle = "Sending Emails"; if($BeenSubmited) { if ($MailFrom) { if (mail($MailTo, $Subject, $Body, "From: $MailFrom")) { print ("<B><CENTER><FONT COLOR=BLUE>your email has been sent</FONT></CENTER></B>n"); } else { print ("<B><CENTER><FONT COLOR=BLUE>your email has not been sent due to a system error!</FONT></CENTER></B>n"); } } else { print ("<B><CENTER><FONT COLOR=RED>please fill in the required fields!</FONT></CENTER></B>n"); } } ?> <html> <head></head> <body> <FORM ACTION="email.php" METHOD=POST> <INPUT TYPE=HIDDEN NAME=MailTo VALUE=guillowind@aol.com> your email address:<INPUT TYPE=TEXT NAME="MailFrom" SIZE="50"><BR> email subject:<INPUT TYPE=TEXT NAME="Subject" SIZE="50"><BR> email body:<TEXTAREA NAME="Body" ROWS="10" COLS="50"> </TEXTAREA><P> <INPUT TYPE=HIDDEN NAME=BeenSubmited VALUE=TRUE> <INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Submit!"> </FORM> Quote Link to comment Share on other sites More sharing options...
johnnyv Posted November 5, 2002 Report Share Posted November 5, 2002 for the mail function in php to work it uses the server's smtp server to send the mail. i think it works for sendmail/postfix and some other sendmail compatible smtp servers. i think it works by default if you have one on the supported smtp servers on the server. http://www.php.net/manual/en/ref.mail.php if you don't have a sendmail compatible smtp server on the server where the script is held i believe you can set your php.ini file to use another servers smtp server Name Default Changeable SMTP "localhost" PHP_INI_ALL smtp_port "25" PHP_INI_ALL sendmail_from NULL PHP_INI_ALL sendmail_path DEFAULT_SENDMAIL_PATH PHP_INI_SYSTEM You would change the "localhost" to the address of the other smtp server. hope this helps Quote Link to comment Share on other sites More sharing options...
Guest tezca Posted November 6, 2002 Report Share Posted November 6, 2002 no, I have a supported server came right off the cds, thing is I upgraded the php packages, and after doing a little studying seems their are some insecurites with the mail function which is why they changed the code a bit also global form variables are turned off by default and need to be turned on in php.ini sendmail works on my machine, it works with perl just not with php the way i was used to Its allot more complicated now from what I read, just wish I could find a clear example, Quote Link to comment Share on other sites More sharing options...
Guest tezca Posted November 6, 2002 Report Share Posted November 6, 2002 after checking the mail for my root account it seems the php pages attempt to mail the info but are refused by a isp mailserver (aol.com) becuase of "dns" hmmmmmmmmmmm, again perhaps the above solution will help. the pages are delivered to the postmaster and then forwarded to me on the local machine first i think i'll try delivering to a local account. also seems that the reason the perl script works is that it acts as a user and performs a sendmail transaction as would an ordinary user "helo localhost", mail from: etc. if anybody knows a phpscript that includes headers I would greatly apprieciate it the script should contact sendmail and issue the appriate commands something like <?php $SMTP_SERVER = "localhost"; helo $SMTP_SERVERn; mail from: echo $mailfromn; rcpt to: echo $mailton; datan; echo ("$firstname" . "$lastname", . "$items" ); .n; ?> something like that? Quote Link to comment Share on other sites More sharing options...
johnnyv Posted November 6, 2002 Report Share Posted November 6, 2002 Oh globals thats not a problem! You know that you post variables are in the $_POST array which is a super global. Too access you variables just do $_POST["MailTo"], and you can access the value for "MailTo" That's it. Quote Link to comment Share on other sites More sharing options...
johnnyv Posted November 6, 2002 Report Share Posted November 6, 2002 <?php $PageTitle = "Sending Emails"; if($_POST["BeenSubmited"]) { if ($_POST["MailFrom"]) { if (mail($_POST["MailTo"], $_POST["Subject"], $_POST["Body"], "From: $_POST["MailFrom"]")) { print ("<B><CENTER><FONT COLOR=BLUE>your email has been sent</FONT></CENTER></B>n"); } else { print ("<B><CENTER><FONT COLOR=BLUE>your email has not been sent due to a system error!</FONT></CENTER></B>n"); } } else { print ("<B><CENTER><FONT COLOR=RED>please fill in the required fields!</FONT></CENTER></B>n"); } } ?> <html> <head></head> <body> <FORM ACTION="email.php" METHOD=POST> <INPUT TYPE=HIDDEN NAME=MailTo VALUE=guillowind@aol.com> your email address:<INPUT TYPE=TEXT NAME="MailFrom" SIZE="50"><BR> email subject:<INPUT TYPE=TEXT NAME="Subject" SIZE="50"><BR> email body:<TEXTAREA NAME="Body" ROWS="10" COLS="50"> </TEXTAREA><P> <INPUT TYPE=HIDDEN NAME=BeenSubmited VALUE=TRUE> <INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Submit!"> </FORM> personally i prefer to use 2 pages one for the form, and one for the processing page and use javascript for checking that all form elements are filled out before submit occurs. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.