mc77 Posted October 29, 2013 Share Posted October 29, 2013 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: <?phpif ($_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>"); }?> Quote Link to comment Share on other sites More sharing options...
mentalist Posted October 29, 2013 Share Posted October 29, 2013 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... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.