Jump to content

[SOLVED] HELP ME!!! PHP CODING


zapper13

Recommended Posts

PLease help me cuz i am a noob with php codes. I self read a little on php code and came up with this. However, when i clicked on submit, the error page appears instead of your mail was sent successfully. Where did i go wrong? I followed the instructions completely. I am using yahoo webhosting.

 

<?php

 

$to = "[email protected]";

$subject = "nothing";

$text = $_REQUEST['text'];

$email = $_REQUEST['email'];

$list = $_REQUEST['list'];

$contactno = $_REQUEST['contactno'];

$headers = "From: $email";

$sent = mail($to, $subject, $text, $email, $list, $contactno, $headers);

if($sent)

{print "your mail was sent successfully"; }

else

{print "error"; }

 

 

?>

Link to comment
https://forums.phpfreaks.com/topic/148935-solved-help-me-php-coding/
Share on other sites

This is my html code

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

</head>

 

<body>

<form id="form1" name="form1" method="post" action="contactprocess.php">

  <p>

    <label>

      <input type="text" name="text" id="text" />

    </label>

  </p>

  <p>

    <label>

      <input type="text" name="email" id="email" />

    </label>

  </p>

  <p>

    <label>

      <select name="list" id="list">

        <option value="hello">hello</option>

        <option value="bye">bye</option>

        <option value="huh">huh</option>

      </select>

    </label>

  </p>

  <p>

    <label>

      <input type="text" name="contactno" id="contactno" />

    </label>

  </p>

  <p>

    <label>

      <input type="submit" name="submit" id="submit" value="Submit" />

    </label>

  </p>

</form>

</body>

</html>

 

In the future, please use [ code ][ /code ] tags (without the spaces) when posting. There is a button with a # on it when you are posting that will insert them for you.

 

I just loaded this up for a test, and it worked for me:

<?php
  if($_SERVER['REQUEST_METHOD'] == 'POST'){
   $to = "[email protected]";
   $subject = "nothing";
   $text = $_REQUEST['text'];
   $email = $_REQUEST['email'];
   $list = $_REQUEST['list'];
   $contactno = $_REQUEST['contactno'];
   $headers = "From: $email";
   $sent = mail($to, $subject, "$text\n$email\n$list\n$contactno", $headers);
   if($sent)
   {print "your mail was sent successfully"; }
   else
   {print "error"; }
   exit;
  }

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <p>
    <label>
      <input type="text" name="text" id="text" />
    </label>
  </p>
  <p>
    <label>
      <input type="text" name="email" id="email" />
    </label>
  </p>
  <p>
    <label>
      <select name="list" id="list">
        <option value="hello">hello</option>
        <option value="bye">bye</option>
        <option value="huh">huh</option>
      </select>
    </label>
  </p>
  <p>
    <label>
      <input type="text" name="contactno" id="contactno" />
    </label>
  </p>
  <p>
    <label>
      <input type="submit" name="submit" id="submit" value="Submit" />
    </label>
  </p>
</form>
</body>
</html>

oh thanks you so much guys. i finally managed to get it to work. the problem was actually the $header part. somehow yahoo web hosting disable unknown email addresses to be sent so when i change that field to "From: $to" as revraz stated, it worked perfectly.

 

however i got another question. i will like to know how to instead of printing "your email has been sent successfully" or "error", the submit button will load another webpage

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.