Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 244
  • Last Modified:

Sending Email From Webpage

I want to give a user the ability to send themselves an E-Mail from a webpage.  I also want the Name. Address, Phone of the restaurant to be in the content part of the E-Mail.  This info comes from an online MySQL database.  How would I do this?
0
DS928
Asked:
DS928
  • 3
  • 2
1 Solution
 
Jagadishwor DulalBraces MediaCommented:
Fetch the required fields from database as you write you want name, address etc. Keep them in a variable and you can use simple php mail function like:

<?php
$to      = 'to@example.com';
$subject = 'the subject';
$message = 'Hello';
$message.= "Name". $name."\r\n";
$message.= "Address".$address."\r\n";//Like this line you can add name address value in message.


$headers = 'From: to@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

Open in new window

0
 
DS928Author Commented:
Thank you.  I am still having difficulty.  Go to this page..
http://www.menuhead.com/bigsearch.php

Selct Baltimore / American / Click on Arrow.......
Select 13.5% Winebar

Towards the bottom right I have an Email Button.  I want the ability for the user to Email the Name and Address of the restaurant to themseleves.  Here is the code behind the button.... $Lid is the variable that contains the ID of the restaurant....

<td width="300"><div align="center">
	<a href="mailto:' . $Email . '">' . $Email . '</a>
	<?php
		$to      = 'to@example.com';
		$subject = 'the subject';
		$message = 'Hello';
		$message.= "Name". $name."\r\n";
		$message.= "Address".$address."\r\n";//Like this line you can add name address value in message.


		$headers = 'From: to@example.com' . "\r\n" .
    	'Reply-To: webmaster@example.com' . "\r\n" .
    	'X-Mailer: PHP/' . phpversion();

		mail($to, $subject, $message, $headers);
	?>;
    <img src="Images/Buttons/BigRestMail.png" alt="" width="220" height="70" border="0"/></a></div></td>

Open in new window

0
 
Jagadishwor DulalBraces MediaCommented:
You did not read my post carefully, You are using variable in single quote that is problem do not use $email in '$email' it will be as a string just use $email only.

$message.= "Name". $name."\r\n"; 

Open in new window

You need to add variable which contain name here in $name, like rest of the works address and others.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
DS928Author Commented:
Like this?

<a href="mailto: . $Email . "> . $Email . </a>

But still not opening.
0
 
DS928Author Commented:
Ok, The outlook link is working.  But the Subject , Message and Header is not populating.

<td width="300"><div align="center">
	<a href="mailto:">
    <?php
		$Lid = 'Lid';
		$to      = 'to@example.com';
		$subject = 'MENUHEAD.COM';
		$message = 'Hello';
		$message.= "Name". $name."\r\n";
		$message.= "Address".$address."\r\n";//Like this line you can add name address value in message.


		$headers = 'From: to@example.com' . "\r\n" .
    	'Reply-To: webmaster@example.com' . "\r\n" .
    	'X-Mailer: PHP/' . phpversion();

		mail($to, $subject, $message, $headers);
	?>
    <img src="Images/Buttons/BigRestMail.png" alt="" width="220" height="70" border="0"/></a></div>
    </td>

Open in new window

0
 
Ray PaseurCommented:
Here is the essential example of the form-to-email script.  Note that the first thing you will find with any such script that allows a client to enter the email will be that the script will immediately come under attack from spammers who are looking for an open relay.  Be absolutely certain that you lock the script down with every security measure you can use!.

To get the "To" address into the mail command, you would just add it to the HTML form and pick the data out of the POST request array.

<?php // RAY_form_to_email.php
error_reporting(E_ALL);


// SEND MAIL FROM A FORM


// REQUIRED VALUES ARE PREPOPULATED - CHANGE THESE FOR YOUR WORK
$from  = "NoReply@Your.org";
$subj  = "Contact Form";

// THIS IS AN ARRAY OF RECIPIENTS - CHANGE THESE FOR YOUR WORK
$to[]  = "You@Your.org";
$to[]  = "Her@Your.org";
$to[]  = "Him@Your.org";


// IF THE DATA HAS BEEN POSTED
if (!empty($_POST['email']))
{
    // DISABLED ON THE SERVER SIDE
    var_dump($_POST);
    die(' DISABLED');

    // CLEAN UP THE POTENTIALLY BAD AND DANGEROUS DATA
    $email      = clean_string($_POST["email"]);
    $name       = clean_string($_POST["name"]);
    $telephone  = clean_string($_POST["telephone"]);

    // CONSTRUCT THE MESSAGE THROUGH STRING CONCATENATION
    $content    = NULL;
    $content   .= "You have a New Query From $name" . PHP_EOL . PHP_EOL;
    $content   .= "Tel No: $telephone" . PHP_EOL;
    $content   .= "Email: $email" . PHP_EOL;

    // SEND MAIL TO EACH RECIPIENT
    foreach ($to as $recipient)
    {
        if (!mail( $recipient, $subj, $content, "From: $from\r\n"))
        {
            echo "MAIL FAILED FOR $recipient";
        }
        else
        {
            echo "MAIL WORKED FOR $recipient";
        }
    }

    // PRODUCE THE THANK-YOU PAGE
    echo '<p>THANK YOU</p>' . PHP_EOL;
}


// A FORM TO TAKE CLIENT INPUT FOR THIS SCRIPT
$form = <<<ENDFORM
<form method="post">
Please enter your contact information
<br/>Email: <input name="email" />
<br/>Phone: <input name="telephone" />
<br/>Name:  <input name="name" />
<br/><input type="submit" />
</form>
ENDFORM;

echo $form;


// A FUNCTION TO CLEAN UP THE DATA - AVOID BECOMING AN OPEN-RELAY FOR SPAM
function clean_string($str)
{
    // IF MAGIC QUOTES IS ON, WE NEED TO REMOVE SLASHES
    $str = stripslashes($str);

    // REMOVE EXCESS WHITESPACE
    $rgx
    = '#'                // REGEX DELIMITER
    . '\s'               // MATCH THE WHITESPACE CHARACTER(S)
    . '\s+'              // MORE THAN ONE CONTIGUOUS INSTANCE OF WHITESPACE
    . '#'                // REGEX DELIMITER
    ;
    $str = preg_replace($rgx, ' ', $str);

    // REMOVE UNWANTED CHARACTERS
    $rgx
    = '#'                // REGEX DELIMITER
    . '['                // START OF A CHARACTER CLASS
    . '^'                // NEGATION - MATCH NONE OF THE CHARACTERS IN THIS CLASS
    . 'A-Z0-9'           // KEEP LETTERS AND NUMBERS
    . '"'                // KEEP DOUBLE QUOTES
    . "'"                // KEEP SINGLE QUOTES
    . '@&+:?_.,/\-'      // KEEP SOME SPECIAL CHARACTERS (ESCAPED HYPHEN)
    . ' '                // KEEP BLANKS
    . ']'                // END OF THE CHARACTER CLASS
    . '#'                // REGEX DELIMITER
    . 'i'                // CASE-INSENSITIVE
    ;
    $str = preg_replace($rgx, NULL, $str);

    return trim($str);
}

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now