Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Help with email form using PEAR

authentication

  • Please log in to reply
1 reply to this topic

#1 elliottveares

elliottveares

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 56 posts

Posted 19 November 2011 - 05:11 PM

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
  • 0

#2 Alexander

Alexander

    YOL9

  • Moderator
  • 3963 posts
  • Location:Vancouver, Eh! Cleverness: 200
  • Programming Language:C, C++, PHP, Assembly

Posted 20 November 2011 - 11:51 PM

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

All new problems require investigation, and so if errors are problems, try to learn as much as you can and report back.






Also tagged with one or more of these keywords: authentication

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download