I need help with PHP code -
Nenad - 08.01.2012
Can someone tell me what is wrong in this code:
PHP код:
<?php
if (isset($_REQUEST['email']))
{
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
mail("you@domain.com", "$subject",
$message, "From:" . $email);
echo "Thank you for contacting us!<br />We will try to answer your report.";
}
else
{
echo "<form method='post' action='mailform.php'>
Email: <input name='email' type='text' /><br />
Subject: <input name='Subject' type='text' /><br />
Message:<br />
<textarea name='message' rows='15' cols='40'>
</textarea><br />
<input type='Submit' name='submit' value='Send e-mail'/>
</form>";
}
?>
When I press send e-mail it doesn't want to send e-mail even tho it says it is sent. And it doesn't return to the mailform if I didn't typed email, subject and message, it just says "Thank you for contacting us! We will try to answer your report." (its the message I placed in echo function). If anyone can help me I will +rep him
Re: I need help with PHP code -
[Diablo] - 08.01.2012
have you tried replacing $_REQUEST with $_POST ?
Re: I need help with PHP code -
Nenad - 08.01.2012
Yes I did. It gives me same results.
Re: I need help with PHP code -
Kwarde - 08.01.2012
The email has beent sent to
you@domain.com.
Re: I need help with PHP code -
TheJayMan - 08.01.2012
Hi, are you running this off a web-host or a local server? If it's a local server ensure you have a mail server enabled also.
Re: I need help with PHP code -
Nenad - 08.01.2012
Quote:
Originally Posted by Kwarde
The email has beent sent to you@domain.com.
|
I placed that because I don't want my email to be shown at this forum.
Quote:
Originally Posted by TheJayMan
Hi, are you running this off a web-host or a local server? If it's a local server ensure you have a mail server enabled also.
|
It's on webhost...
Re: I need help with PHP code -
Deagle[WS] - 08.01.2012
You probably used this, right?
http://www.w3schools.com/php/php_secure_mail.asp
Re: I need help with PHP code -
BlackBank - 08.01.2012
PHP код:
<?php
if (isset($_REQUEST['email']))
{
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
mail($email, "$subject",
$message, "From: you@domain.com");
echo "Thank you for contacting us!<br />We will try to answer your report.";
}
else
{
echo "<form method='post' action='mailform.php'>
Email: <input name='email' type='text' /><br />
Subject: <input name='Subject' type='text' /><br />
Message:<br />
<textarea name='message' rows='15' cols='40'>
</textarea><br />
<input type='Submit' name='submit' value='Send e-mail'/>
</form>";
}
?>
Try this code.
I think that you have placed the mail on the wrong place in the function.
http://php.net/manual/en/function.mail.php
Re: I need help with PHP code -
Nenad - 08.01.2012
Quote:
Originally Posted by BlackBank3
PHP код:
<?php
if (isset($_REQUEST['email']))
{
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
mail($email, "$subject",
$message, "From: you@domain.com");
echo "Thank you for contacting us!<br />We will try to answer your report.";
}
else
{
echo "<form method='post' action='mailform.php'>
Email: <input name='email' type='text' /><br />
Subject: <input name='Subject' type='text' /><br />
Message:<br />
<textarea name='message' rows='15' cols='40'>
</textarea><br />
<input type='Submit' name='submit' value='Send e-mail'/>
</form>";
}
?>
Try this code.
I think that you have placed the mail on the wrong place in the function.
http://php.net/manual/en/function.mail.php
|
That won't work. It's preatty much the same.
Quote:
Originally Posted by Deagle[WS]
|
No, but that code is similar to mine and I tested it and it doesn't work either :S
Re: I need help with PHP code -
Sinner - 08.01.2012
You did not add sufficient headers to the email, it requires more then just the "From:". Try this header:
PHP код:
$headers = 'From: your_email@yourhost.com' . "\r\n" .
'Reply-To: your_email@yourhost.com . "\r\n" .
'X-Mailer: PHP/' . phpversion();
Send an email with the following function:
PHP код:
mail($to, $subject, $body)