Jump to content

Recommended Posts

Hey guys, I'm trying to make a simple email script and I'm sure I'm overlooking something easy and I know one of you PHP Gurus can get this in a second.

 

I have my HTML file with a form action for mailer.php the code for mailer.php is

 

<?php
$to      = 'email@email.com';
$subject = 'hello';
$message = 'this is the email message to php freaks.!';
$headers = 'From: email@emailer.net' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

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

 

My question is, on the HTML file in the form, How can I get data from the website to be put into $to $subject, etc. I'm not sure how to link the two so that data i type in the text field will replace whats in the mailer.php script. I set the text field name to subject, etc but I'm just not knowledgeable enough to get it.

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/63262-php-newbie/
Share on other sites

I'll get you started....

 

The html file:

<form name="email_form" method="post" action="send_email.php">

Email address: <input type="text" name="email_to" size="50"/>

<!-- subject and message inputs go here -->

<p><input type="submit" name="submit" id="submit" value="Submit;" /></p>

</form>

 

the php file called "send_email.php"

<?php

$email_to = mysql_real_escape_string($_POST['email_to']); 
if (empty($email_to))
{ die('Email is empty. Please go <a href="javascript:history.back(-1);">back</a>.');
}

//  add above for subject and message

$to      = 'email@email.com';
$subject = 'hello';
$message = 'this is the email message to php freaks.!';
$headers = 'From: email@emailer.net' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

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

 

Link to comment
https://forums.phpfreaks.com/topic/63262-php-newbie/#findComment-316294
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.