dark k58 Posted April 25, 2012 Share Posted April 25, 2012 ok I made a contact us page where the user has to enter his email and message to send it this is the code for the contact us page <?php include "../storescripts/user_php_login.php"; ?> <?php error_reporting(E_ALL); ini_set('display_errors', '1'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Contact Page</title> <link rel="stylesheet" href="../style/style.css" type="text/css" media="screen" /> </head> <body> <div align="center" id="wrapper"> <?php include_once("template_header_user_login.php");?> <div id="content"> <table width="100%" border="0" cellspacing="0" cellpadding="10"> <tr> <td width="32%" valign="top"><form method="post" action="../storescripts/contact.php"> Email: <input name="email" type="text"><br> Message:<br> <textarea name="message" rows="15" cols="40"></textarea><br> <input type="submit"> </form> </td> <td width="35%" valign="top"></td> <td width="33%" valign="top"></td> </tr> </table> </div> <?php include_once("template_footer_user_login.php");?> </div> </body> </html> and this is the php that sends the message <?php $to = "[email protected]"; $subject = "Contact Us"; $email = $_REQUEST['email'] ; $message = $_REQUEST['message'] ; $headers = "From: $email"; $sent = mail($to, $subject, $message, $headers) ; if($sent) {print "Your mail was sent successfully"; } else {print "We encountered an error sending your mail"; } ?> I want it so when the user is logged in it would bull his email from the database so he doesn't need to enter it so all he does is write the message and click send thankyou Quote Link to comment https://forums.phpfreaks.com/topic/261604-how-to-use-the-email-from-mysql/ Share on other sites More sharing options...
gevensen Posted April 25, 2012 Share Posted April 25, 2012 check this out this something i am working on implementing Using phpmailer. this is all from here 1)Download PHPMailer http://phpmailer.sourceforge.net/ 2) Extract to folder phpmailer 3) Create a file email.php 4) Paste this code and change the values in blue as you need (I modified the sample code given on the PHPMailer homepage) require("phpmailer/class.phpmailer.php"); $mail = new PHPMailer(); $mail->IsSMTP(); // send via SMTP IsSMTP(); // send via SMTP $mail->SMTPAuth = true; // turn on SMTP authentication $mail->Username = "[email protected]"; // SMTP username $mail->Password = "password"; // SMTP password $webmaster_email = "[email protected]"; //Reply to this email ID $email="[email protected]"; // Recipients email ID $name="name"; // Recipient's name $mail->From = $webmaster_email; $mail->FromName = "Webmaster"; $mail->AddAddress($email,$name); $mail->AddReplyTo($webmaster_email,"Webmaster"); $mail->WordWrap = 50; // set word wrap $mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment $mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // attachment $mail->IsHTML(true); // send as HTML $mail->Subject = "This is the subject"; $mail->Body = "Hi, This is the HTML BODY "; //HTML Body $mail->AltBody = "This is the body when user views in plain text format"; //Text Body if(!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "Message has been sent"; } ?> 5) Open the file class.smtp.php in phpmailer directory 6) Paste this code $host = "ssl://smtp.gmail.com"; $port = 465; before the line 104 #connect to the smtp server Hint: Search for #connect 7) Open this page in browser and it will send the email using GMail. Hint: When you want to email the details from a form, set the variables using the form variables. eg. $mail->Username=$_POST['email'] Quote Link to comment https://forums.phpfreaks.com/topic/261604-how-to-use-the-email-from-mysql/#findComment-1340536 Share on other sites More sharing options...
scootstah Posted April 26, 2012 Share Posted April 26, 2012 You'll need some way of referencing the logged-in user. Usually this is done by adding the user's ID to a session variable. Once you have that you can select that user's information, thus getting his email from the database. From there it's just a matter of setting the $to variable to the email you pulled out. Quote Link to comment https://forums.phpfreaks.com/topic/261604-how-to-use-the-email-from-mysql/#findComment-1340552 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.