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 root@generic.com 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 = "root@generic.com";
 $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 = "root@generic.com";
 $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
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 "root@generic.com" to your email address for that site, e.g. admin@mydomain.biz, and also change the TO string too to where you want it to go to...

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.