Jump to content

Recommended Posts

Dear all,

 

I bought two books on PHP and followed the author's instructions closely but I can never be successful in submitting a form.  The information on the form is supposed to be sent as a string through email once users click the "submit" button.  Based on the books, I have configured the php.ini file and so on but things never worked.  I'm too disappointed.  Any ideas or suggestions ?

 

Many thanks!

Tommy

Link to comment
https://forums.phpfreaks.com/topic/62572-how-to-send-a-form-as-an-email/
Share on other sites

Please submit your code where you set the headers and mailto scripts..

 

Hi: Here's my code.  Hope you can help.  Many thanks and appreciations!  Tommy

 

<?php

if (array_key_exists('ewComments', $_POST)) {

  // mail processing script

  // initialize variables

  $to = 'kngo252@yahoo.com';

  $subject = 'Feedback from East-West Seasons';

 

  // build the message

  $message = 'From: '.$_POST['name']."\n\n";

  $message .= 'Email: '.$_POST['email']."\n\n";

  $message .= 'Comments: '.$_POST['message'];

 

  // send the email

  mail($to, $subject, $message);

}

?>

<!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=iso-8859-1" />

<title>East-West Seasons</title>

<?php include('style_rules_monthly.php'); ?>

</head>

 

<body>

<div id="wrapper">

  <div id="titlebar"><img src="images_common/<?php echo $theme; ?>_top.jpg" alt="East-West Seasons" width="738" height="122" /></div>

  <div id="maincontent">

    <div id="nav">

      <ul>

        <li><a href="index.php">Home</a></li>

        <li><a href="news.php">News</a></li>

        <li><a href="blog.php">Blog</a></li>

        <li><a href="gallery.php">Gallery</a></li>

        <li><a href="contact.php">Contact</a></li>

      </ul>

    </div>

    <h1>Send Us Your Comments</h1>

    <p>We hope you have enjoyed this site. If you have any comments, or would like further information, please use the following form. East-West Seasons will not use your email address for any other purposes than replying to you.</p>

    <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" name="contactForm" id="contactForm">

      <p> </p>

      <p>

        <label for="name">Name:</label>

        <br />

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

      </p>

      <p>

        <label for="email">Email:</label>

        <br />

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

      </p>

      <p>

        <label for="message">Message:</label>

        <br />

        <textarea name="message" cols="60" rows="6" id="message"></textarea>

      </p>

      <p>

        <input name="ewComments" type="submit" id="ewComments" value="Send comments" />

      </p>

    </form>

  </div>

  <div id="footer">

    <p>© 2007 Khiem Ngo </p>

  </div>

</div>

</body>

</html>

Firstly ...under the <form> element, I would place a hidden field, (<input type="hidden" name="action" value="emailform"> ) - maybe your 'submit' button is not working.. Stick the submit buttons as <input type="submit" name="submit" value="submit"> keep it simple then, instead of --  if (array_key_exists('ewComments', $_POST)) {---i would say -- if ($_POST['action'] == "emailform") { bla bla the also place a 'tester'on your mail function like if ( mail($to, $subject, $message);) { echo "hooray!"} else {echo "oh shit!"}

I just tested my site again and this is the error I got:

 

"Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in C:\htdocs\phpdw\contact.php on line 14"

 

I opened php.ini file and did a search on "sendmail_from".  I found that I had set "sendmail_from = tmng2005@yahoo.com".  I'm incorporating your suggestions to the code.  I'm wondering if the problem has anything to do with configuration or setting in the php.ini file.  As far as line 14 in the code is concerned, it is "mail($to, $subject, $message);"  Any further ideas ? !  Thanks.

 

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.