Author Topic: PHP newbie.  (Read 623 times)

0 Members and 1 Guest are viewing this topic.

Offline batorTopic starter

  • Irregular
    • View Profile
PHP newbie.
« on: August 03, 2007, 10:18:16 PM »
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

Code: [Select]
<?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
« Last Edit: August 03, 2007, 10:19:47 PM by bator »

Offline php?

  • Enthusiast
    • View Profile
Re: PHP newbie.
« Reply #1 on: August 03, 2007, 11:43:39 PM »
Try putting this in the php help section :D
My signature used to be inappropriate, but a moderator fixed it for me! Yay!

Offline nirvana4lf

  • Irregular
    • View Profile
Re: PHP newbie.
« Reply #2 on: August 04, 2007, 08:40:42 PM »
try deleting the headers variable. its not a required parameter in the mail(); function

Offline pyrodude

  • Enthusiast
  • Gender: Male
  • Ever wish you were dead? Me too...
    • View Profile
Re: PHP newbie.
« Reply #3 on: August 05, 2007, 04:47:46 PM »
Direct your form to that php file, then use $_POST['your_input_name_here'] to refer to each value.  For example, you could set
Code: [Select]
$to = $_POST['email_to'];
$from = $_POST['email_from'];
$subject = $_POST['subject'];
and so on.

Offline tippy_102

  • Enthusiast
    • View Profile
Re: PHP newbie.
« Reply #4 on: August 05, 2007, 07:20:17 PM »
I'll get you started....

The html file:
Code: [Select]
<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"
Code: [Select]
<?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);
?>

Fur is more actively protested than leather 'cause its easier to harrass rich women than biker gangs.

PHP Freaks Forums

« on: »

Tired of these ads? Purchase a supporter subscription to get rid of them.