I need help with PHP code
#1

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
Reply
#2

have you tried replacing $_REQUEST with $_POST ?
Reply
#3

Yes I did. It gives me same results.
Reply
#4

The email has beent sent to you@domain.com.
Reply
#5

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.
Reply
#6

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...
Reply
#7

You probably used this, right?

http://www.w3schools.com/php/php_secure_mail.asp
Reply
#8

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
Reply
#9

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
Reply
#10

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-MailerPHP/' . phpversion(); 
Send an email with the following function:

PHP код:
mail($to$subject$body
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)