Jump to content

cannot sendmail with php


Guest tezca
 Share

Recommended Posts

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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 :cry: 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, :evil:

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

<?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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...