I actually followed a tutorial which got everything working for me.
I used the code from this tutorial. I already created the form and this is the code for the 'Contact.php' page:
http://php.about.com/od/phpapplications/ss/form_mail_3.htmEverything was working at that point with the exception of actually sending the mail. I believe it's because the SMTP server needs authentication. So then I followed another tutorial, because the site is on a server that has PEAR installed. This is the code I used to authenticate:
http://email.about.com/od/emailprogrammingtips/qt/et073006.htmNow, I got that part of the code to work, and I implanted it into the top part of the 'Contact.php', (and configured the authentication options) it seems to work, but it's not using the data from the form. I know I need to somehow combine these two things, but I'm not sure how.
The overall gist of what i'm trying to do is rather simple...
I'm just creating a form that has a few fields (name, address, etc...) and when the submit button is hit, it should e-mail the info. from those fields to a designated email address. If there is a simpler way of doing this, please let me know.
If you want to see the form that I've actually created, you can view it here:
http://www.smartofficeadvisors.com/survey1.phpFrom there, when the user hits "submit" it transfer the information to:
http://www.smartofficeadvisors.com/contact2.phpfor which the source looks like this:
<!-- The PHP Authentication Script -->
<?php
require_once "Mail.php";
$from = "from <user@dijitalmedia.com>";
$to = "bcast <bcast@smartofficeadvisors
.com>";
$subject = "Pig Card";
$body = "Hi,\n\nHow are you?";
$host = "mail.dijitalmedia.com";
$username = "user@dijitalmedia.com";
$password = "passwordhere";
$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>");
}
?>
<!-- End PHP Authentication Script -->
<!-- The script from the email send tutorial -->
<?php
$to = $_REQUEST['sendto'] ;
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "Chair Survey Results";
$fields = array();
$fields{"Name"} = "Name";
$fields{"industry"} = "Industry";
$fields{"Company"} = "Company";
$fields{"Email"} = "Email";
$fields{"Phone"} = "Phone";
$fields{"list"} = "Mailing List";
$fields{"Message"} = "Message";
$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
$headers2 = "From: info@smartofficeadvisors.c
om";
$subject2 = "Thank you for contacting us";
$autoreply = "Thank you for contacting us.
Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at
www.smartofficeadvisors.com";
if($from == '') {print "You have not entered an email, please go back and try again";}
else {
if($name == '') {print "You have not entered a name, please go back and try again";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{header( "Location:
http://www.smartofficeadvisors.com/thankyou.php" );}
else
{print "We encountered an error sending your mail, please notify ithelp@smartofficeadvisors
.com"; }
}
}
?>
<!-- End Tutorial email sending script -->
I hope all of this has been clear, and I'm certain this should be easy for someone who knows what they're doing. Thanks in advance.
J. Gohil
Start Free Trial