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 = "vagenteh@yahoo.com";

$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
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>

 

Link to comment
Share on other sites

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 = "rhodes.aaron@gmail.com";
   $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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

to send to multiple emails, just update $to:

   $to = "vagenteh@yahoo.com,email@anotherhost.com";

 

to send a separate email (like a thank you for registering), you just copy/paste the code you have already and change the values to what you want

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.