Jump to content

how to use the email from mysql


dark k58

Recommended Posts

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 = "abdulrab09@ymail.com"; $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

Link to comment
Share on other sites

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 = "username@gmail.com"; // SMTP username
$mail->Password = "password"; // SMTP password
$webmaster_email = "username@doamin.com"; //Reply to this email ID
$email="username@domain.com"; // 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']

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.