I have a site hosted with godaddy.com I made a form and i want it to send a confirmation email to whoever filled it out, i tried the mail() function for php in a if-else statement if (mail( $email, "Subject: $subject", $message, "From: $email", "Order : $quantity")) { echo("<p>Message successfully sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); } Code (markup): i kept getting Message delivery failed. Godaddy's gdform.php works, but it only sends the email to me and i cant figure out how to edit it to send the email to the person who filled out the form. i came to a conclusion that SMTP is not working on the page, i tried another piece of code <?php require_once "Mail.php"; $from = "Sandra Sender <sender@example.com>"; $to = "Ramona Recipient <recipient@example.com>"; $subject = "Hi!"; $body = "Hi,\n\nHow are you?"; $host = "mail.example.com"; $username = "smtp_username"; $password = "smtp_password"; $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>"); } ?> Code (markup): but that didnt work either any help would be appreciated thanks
if (mail( $email, "Subject: ".$subject, $message, "From: ".$email, "Order : ".$quantity)) { echo("<p>Message successfully sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); } PHP: Not sure if this is your problem but you were reading the variables as text. use "." to fuse text and variables such as "Order: ".$quantity
$quantity = 10; echo "Quantity : $quantity"; //<----- output Quantity : 10; echo 'Quantity : $quantity'; //<------ output Quantity : $quantity; PHP:
I do not understand you use of the if statement.. I would use the mail command directly.. Or better yet pass the variables to an external file which would send data and display results...
<?php $hostname = gethostbyaddr($REMOTE_ADDR); ?> <?php mail( "info@youdomain.com", "Mail From Your Website ","From IP $REMOTE_ADDR Provider - $hostname Browser - $HTTP_USER_AGENT Name - $name Email - $user_email Address - $address $city - $state -$country Message... $message", "From: mailForm\@yourdomain.com" ); ?> <?php mail( "yourname@yourdomain.com", "Mail From Your Website ","From IP $REMOTE_ADDR Provider - $hostname Browser - $HTTP_USER_AGENT Name - $name Email - $user_email Address - $address $city - $state -$country Message... $message", "From: mailForm\@yourdomain.com" ); ?> <?php echo("<body background=skybluerevgrad.gif><br><p><center><font color=black size=+2 face=arial><b>Thank You!<br> The following message has been sent to Your Company <br> You will recieve a reply as soon as it has been processed...<p> <table width=80%><tr><td> <font color=#0000aa size=+1 face=arial>Name -</font></b> $name<br> <font color=#0000aa size=+1 face=arial><b>Email -</font></b> $user_email<br> <font color=#0000aa size=+1 face=arial><b>Address -</font></b> $address $city $state $zip $country<p> <font color=#0000aa size=+1 face=arial><b>Message...</font><p> </b>$message</td></tr></table>"); ?> Code (markup):
Check to make sure that PEAR Mail package is installed in your server. Make sure you pass correctly the email of the person who filled out your form.
from what i read, PEAR is part of PHP core and does not require installation. and as for the email addresses, i assigned the email to the variable directly and tried it and it wont work.