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 = "myemail@hgmail.com";
$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
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.

Link to comment
Share on other sites

<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 = "myemail@hgmail.com";
$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"; }
?>

 

 

 

 

Link to comment
Share on other sites

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 = "myemail@hgmail.com";
$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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • 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.