Jump to content

[SOLVED] Need help wih mail() ! :(


tomala90

Recommended Posts

Hi guys I really need your help. I am new to PHP.

I am trying to make an email form on my website but I keep getting some kinds of error :(

Here is the code

 

<?php
$to = "[email protected]";
$subject = "Contact Us";
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
$headers = "From: $email";
$sent = mail($to, $subject, $message, $headers) ;
if($sent)
{print "Your mail was sent successfully"; }
else
{print "We encountered an error sending your mail"; }
?>

 

and that is my HTML form

<form action="?" method="post">

Email: <input name="email" type="text"><br>
<input type="submit">

</form>

 

I want to add that I am not running the form and the scrip in one file.

Link to comment
https://forums.phpfreaks.com/topic/179705-solved-need-help-wih-mail/
Share on other sites

There are no parse errors in your php, again I say however that you have no 'message' element in your form.

 

<form action="script.php" method="post">
Email: <input name="email" type="text"><br>
Message: <input name="message" type="text"><br>
<input type="submit">
</form>

 

Notice also that the forms action needs to point to your php script.

<html><body>
<center><br><br><br><br><br><br><br>
<form action="email.php" method="post">
Email: <input name="email" type="text"><br>
Message: <input name="message" type="text"><br>
<input type="submit">
</form>
</body>
</html>

 

<?php
$to = "[email protected]";
$subject = "Contact Us";
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
$headers = "From: $email";
$sent = mail($to, $subject, $message, $headers) ;
if($sent)
{print "Your mail was sent successfully"; }
else
{print "We encountered an error sending your mail"; }
?>

 

 

 

 

There is no way that code could possibly throw that error, but lets indent your code properly so it is more readable and errors are easier to spot.

 

<?php
$to = "[email protected]";
$subject = "Contact Us";
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
$headers = "From: $email";
$sent = mail($to, $subject, $message, $headers) ;
if ($sent) {
    print "Your mail was sent successfully";
} else {
    print "We encountered an error sending your mail";
}
?>

 

Nope, still no errors found.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.