PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I understand you use the mail() to send an email using php, but I need to send an email in a different way. I have a survey that people need to complete, and after they submit the survey an email needs to be sent to them, so each time there will be a new email. Any advice on how I can do this? Below you will see my code:
<?php
$con = mysql_connect("server","user","pass");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
$sql="INSERT INTO Questions (Name, Email, Age, Sex, Income, Edu, Children, Apparel)
VALUES
('$_POST[name]','$_POST[email]','$_POST[age]','$_POST[sex]','$_POST[income]','$_POST[edu]','$_POST[children]','$_POST[apparel]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "Your information has been submitted. Thank you for your time. An email will be sent to the one provided shortly.";
mysql_close($con)
?>
What you'll need to do is set some variables e.g. $firstName, $email etc... to be used dynamically in a seperate php file that will be used to send the email. When i say "dynamically", this basically means that those variables will change according to each form submit.
In terms of actually sending the email, what are you thinking, plain text or html?
<?php
$con = mysql_connect("server","user","pass");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
$sql="INSERT INTO Questions (Name, Email, Age, Sex, Income, Edu, Children, Apparel)
VALUES
('$_POST[name]','$_POST[email]','$_POST[age]','$_POST[sex]','$_POST[income]','$_POST[edu]','$_POST[children]','$_POST[apparel]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "Your information has been submitted. Thank you for your time. An email will be sent to the one provided shortly.";
$subject = 'PUT YOUR SUBJECT HERE';
$message = 'YOU CAN PUT YOUR MESSAGE HERE';
$header = "From: YOUREMAILADDRESSHERE\r\n";
mail($_POST['email'],$subject,$message,$header);
mysql_close($con)
?>