Jump to content

Newbie PHP email Issue


mc77

Recommended Posts

I am new to PHP and have a issue.  My hosting company provided the following code for me to have a contact form and send the values via email.  The problem is that the FROM vale has [email protected] and I would like to have the FROM be the value that is entered in the email field of the contact form.  I image this is a quick fix, but none of my attempts have been successful as of yet.  I appreciate any assistance and here is the code I am using:

 

 

 

<?php
if ($_POST["email"]<>'')
{
 require_once "Mail.php";
 
 $from = "[email protected]";
 $to = "Generic <generic@generic.com>";
 $subject = "Contact us info from Website";
 
 $body = "Name: ".$_POST["name"]."\r\n";
 $body .= "Email: ".$_POST["email"]."\r\n";
 $body .= "Phone: ".$_POST["phone"]."\r\n";
 $body .= "Comment: ".nl2br($_POST["comment"])."";
 
 $host = "mail.generic.com";
 $username = "[email protected]";
 $password = "abcdefghijk";
 
 $headers = array ('From' => $from,'To' => $to, 'Subject' => $subject);
 $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password));
 
 $mail = $smtp->send($to, $headers, $body);
 
 if (PEAR::isError($mail)) {
   echo("<p>" . $mail->getMessage() . "</p>");
  } else {
   echo("<p>Message successfully sent!</p>");
   }
?>
Link to comment
https://forums.phpfreaks.com/topic/283406-newbie-php-email-issue/
Share on other sites

But they aren't sending the email, the server is, their email should be part of the message if this is a contact form!

 

Also you should change the string "[email protected]" to your email address for that site, e.g. [email protected], and also change the TO string too to where you want it to go to...

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.