Jump to content

Help with email form using PEAR

- - - - -

  • Please log in to reply
1 reply to this topic

#1
elliottveares

elliottveares

    Newbie

  • Members
  • Pip
  • 5 posts
Hi, I found some PHP code of the internet that sends data from a form in an email using pear. It works - well nearly, the email sends ok but the email i revive does not have any of the data from the from.

Here is the html part of the form



<html>


<head>


</head>




<body>


<form name="contactform" action="send_form_email.php" method="post">


	<!-- The following line specified which fields are required. List


	field names EXACTLY as they are named in the form. -->


	<input type="hidden" name="Required" value="Name,Email,Phone,Comments">


	<p>Name: <input name="Name" size="25"> <span class="small">required</span></p>


	<p>Company: <input name="Company" id="Company" size="25"></p>


	<p>E-mail: <input name="Email" size="25"> <span class="small">required</span></p>


	<p>Phone: <input name="Phone" size="25"> <span class="small">required</span></p>


	<p>How you heard of us: <input name="Howheard" size="25"></p>


	<p>Comments:</p>


	<p><textarea name="Comments" rows="5" cols="30"></textarea> <span class="small">required</span></p>


	<p><input type="submit" value="Submit" name="submitform"><input type="reset" value="Reset" name="reset"></p>


</form>


</BODY>


</HTML>



And here is the PHP script for it.



<?php


	error_reporting(E_ALL ^ E_NOTICE);


	$mailTo = "MY GMAIL EMAIL ADDRESS"; // The address that will receive form submissions

	$mailSubject = "christmas"; // Whatever you want

	$mailHost = "ssl://smtp.gmail.com"; // Usually looks like mail.yourhost.com

	$mailPort = "465"; // Usually 25

	$mailAuth = true; // "true" if your mail server requires authentication, "false" if not

	$mailPassword = "MY GMAIL PASSWORD"; // The mail password associated with $mailTo





	$name = $HTTP_POST_VARS['Name'];

	$company = $HTTP_POST_VARS['Company'];

	$email = $HTTP_POST_VARS['Email'];

	$comments = $HTTP_POST_VARS['Comments'];

	$howheard = $HTTP_POST_VARS['Howheard'];

	$reqFields = $HTTP_POST_VARS['Required'];



	$date = date("l jS F Y, g:i A");


       {


		$browser = $HTTP_USER_AGENT;

		$ip = $REMOTE_ADDR;


		// Build the email.

		$body = "            Name: $Name

         Company: $Company

           Email: $Email

           Phone: $Phone

Heard of us from: $howheard

----- Comments -----

$Comments

--------------------

            Date: $date

         Browser: $browser

         User IP: $ip";


		include("mail.php");

		

		$headers["From"]    = $mailTo;

		$headers["To"]      = $mailTo;

		$headers["Subject"] = $mailSubject;

		$params["host"] = $mailHost;

		$params["port"] = $mailPort;

		$params["auth"] = $mailAuth;

		$params["username"] = $mailTo;

		$params["password"] = $mailPassword;


		$mail_object =& mail::factory("smtp", $params);

		$mail_object->send($mailTo, $headers, $body);




?>

        <h1>Thank You</h1>

        <p>Thank you for contacting us.  We will be in touch with you shortly.</p>


<?php

	}

?>





So any help is much appreciated to get this working, I would also like the from field in my revived email to be the email entered in in the form.

Help Appreciated: Elliott Veares

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
Hello Elliott,

Your code uses old global variables, of which are not recommended and may even have been disabled since their deprecation.

i.e.
$HTTP_POST_VARS['key'] should be the superglobal array $_POST['key']
$REMOTE_ADDR should be the value $_SERVER['REMOTE_ADDR']

The manual references to these superglobals can be reviewed to update your script, see if it runs and post back if not.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users