Please login or register.

Login with username, password and session length
Advanced search  

News:

We are constantly trying to improve phpfreaks and these forums, so feel free to go to the PHPFreaks Comments/Suggestions board and point out anything you'd like to see different!

Maintenance Notice

PHPFreaks has successfully moved to a new Dedicated Server, hosted by Server Powered. Please help support future upgrades by Donating.

Author Topic: PHP newbie.  (Read 483 times)

0 Members and 1 Guest are viewing this topic.

bator

  • New Member
  • Offline Offline
  • Posts: 1
    • View Profile
PHP newbie.
« on: August 03, 2007, 09: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, 09:19:47 PM by bator »
Logged

php?

  • Member
  • Offline Offline
  • Posts: 243
    • View Profile
Re: PHP newbie.
« Reply #1 on: August 03, 2007, 10:43:39 PM »
Try putting this in the php help section :D
Logged

My signature used to be inappropriate, but a moderator fixed it for me! Yay!

nirvana4lf

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

pyrodude

  • Member
  • Offline Offline
  • Gender: Male
  • Posts: 94
  • Ever wish you were dead? Me too...
    • View Profile
Re: PHP newbie.
« Reply #3 on: August 05, 2007, 03: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.
Logged

tippy_102

  • Member
  • Offline Offline
  • Posts: 445
    • View Profile
Re: PHP newbie.
« Reply #4 on: August 05, 2007, 06: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);
?>

Logged

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

Page created in 0.039 seconds with 19 queries.