PHP n00b

the mail() function

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Thu May 24, 2012 10:12 am

PHP n00b

Postby pacenvtechinc » Thu May 24, 2012 10:56 am

First off, I'm not a web designer -- he's on vacation -- and I've been tasked with making a really simple modification to the mailer. Basically, we have a form on a web page with ~24ish objects (fields, checkboxes, etc). When the form is posted and mailed, a hard-coded subject is added to the email, and I want to modify it to include values from a couple of fields on the form. See pseudocode below for a better idea and current mailer code below that. There's a [computer] language barrier for me, dunno how to translate my pseudocode into PHP. Any help would be greatly appreciated.

Ex. Form: forename surname company address, city, state, zip phone email


Code: Select all

dim to as string
dim ip as string
dim subj as string
dim msg as string
dim br as string

to = ""
br = chr(13) 'carriage return/linefeed

for each field in form.objects
  if field <> "" then 'skip empty fields
    msg = msg & & ": " & field.value & br
    if = "forename" or = "surname" or = "company" then 'add to subj
      subj = subj & field.value & " "
    end if
  end if
next field

'add date/timestamp & ip
msg = "RFQ Below received at: " & date & " " & time & "from IP: " & ip & br & br & msg
subj = "PCA RFQ from " & subj

mail (to, subj, msg)
header ("Location:")


Code: Select all

$to = "";
$subj = "";

$date = date ("l, F jS, Y");
$time = date ("h:i A");

$msg = "";

foreach ($_POST as $key => $value) {if (!(empty($value))) {$msg .= $key . ": " . $value . "\n";}}
if (!(empty($msg))) {
   $msg = "RFQ Below received at: " . $date . " at " . $time . " from " . $ip . "\n\n" . $msg;
   mail ($to, $subj, $msg);
   header ("Location:");}

User avatar
New php-forum User
New php-forum User
Posts: 86
Joined: Mon Jun 04, 2012 10:05 pm
Location: Ankara, Turkey

Re: PHP n00b

Postby ejsexton82 » Tue Jun 05, 2012 10:33 am

The form field values are stored in the $_POST variable. You probably see the field names in the email which is sent out, which probably looks something like this:

Code: Select all

RFQ Below received at: Tuesday, June 5th at 2012 at 9:32 PM from

forename: field value
surname: field value
company: field value

So all you would have to do is pick out the names of the fields, pull the values from the $_POST variable, and shove them into the $subj variable:

Code: Select all

$subj = $_POST['forename'] . ' ' . $_POST['surname'] . ' at ' . $_POST['company'];

Return to “PHP coding => Mail”

Who is online

Users browsing this forum: No registered users and 0 guests