/    Sign up×
Community /Pin to ProfileBookmark

Don’t know how to format PHP email with subheadings

Hi all. I know nothing about PHP so I’m sure this is a breeze for most of you. I can’t find a tute for adding subtitles to the output of my php email that was kindly supplied to me. I just need the subheadings “Name:, Company:, Email:, Phone:, Enquiry:” added before whatever the visitor enters on the email. Please find the script below:

<?php
$sendTo = “[email protected]“;
$subject = “web site enquiry form”;
$from_address = @$HTTP_POST_VARS[’email’];
$headers = “From: ” . $_POST[“firstName”] .” “. $_POST[“lastname”] . “<” . $_POST[“email”] .”>rn”;
$headers .= “Reply-To: ” . $_
POST[“email”] . “rn”;
$headers .= “Return-path: ” . $_POST[“email”];

$body = $_POST[“name”].”nn”;
$body .= $_
POST[“company”].”nn”;
$body .= $_POST[“email”].”nn”;
$body .= $_
POST[“phone”].”nn”;
$body .= $_POST[“enquiry”];

mail($sendTo, $subject, $body, $headers);

?>

I think it has something to do with the “$body =” part but I aren’t sure how to include the subheadings. I have tried a few things but didn’t even receive the response email after doing the changes. I hope this is clear. Any help much appreciated.

Cheers
Lance

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogSep 29.2004 — I might do something like this:
[code=php]
<?php
$sendTo = "[email protected]";
$subject = "DNA Design web site enquiry form";
$from_address = @$HTTP_POST_VARS['email'];
$headers = "From: " . $_POST["firstName"] ." ". $_POST["lastname"] . "<" . $_POST["email"] .">rn";
$headers .= "Reply-To: " . $_POST["email"] . "rn";
$headers .= "Return-path: " . $_POST["email"];

$body = <<<EOD
Name: {$_POST["name"]}

Company: {$_POST["company"]}

Email: {$_POST["email"]}

Phone: {$_POST["phone"]}

Enquiry: {$_POST["enquiry"]}
EOD;

mail($sendTo, $subject, $body, $headers);
?>
[/code]
Copy linkTweet thisAlerts:
@yunaSep 29.2004 — [B]Concerning the line

$headers .= "Return-path: " . $_POST["email"]; [/B]


Generally speaking, the "Return-Path" header is not something you can control. To understand why, we need to talk a bit first about how mail is sent.

You can think of email as analogous to postal mail. There's an "envelope" that contains a "message." The envelope is created during the (SMTP) exchange between the sending and receiving server. Just as you can put your return address on an envelope to send grandma a letter from your child, so, too, SMTP creates an "envelope sender" that may or may not match the address found in the "From:" header within the body of the message itself. The envelope sender usually receives any errors sent back by the receiving server (e.g, user unknown, user over quota, blocked sender IP address, etc.) during the SMTP exchange.

These issues are especially relevant when the envelope sender is a web application. Let's take as an example Apache+PHP running on some *nix flavor like Linux or Solaris. The web server software (httpd) typically runs as a low-privileged user on the server for security reasons. Apache httpd, for instance, starts up as the "root" (administrator) user, but then switches over to running as the low-privileged user. Let's call this user "apache". When you use the mail() function in PHP, the SMTP envelope sender will typically be "[email protected]" regardless of what you put in the "From:" headers. Thus the value of the Return-Path header will also be "[email protected]," and since the apache user doesn't have administrative privileges, it can't change the Return-Path header to something you'd prefer like "[email protected]".

It is possible for the server administrator to grant userland applications permission to change the SMTP sender address. For instance, I permit my mailing listserver software to do this so that delivery errors get sent to the various list managers. However no security-conscious web server administrator would grant similar privileges to a web server because this would open up her server to various spam and virus exploits.

So all this is a long way of saying not to bother with trying to set the Return-Path; it won't work and may generate errors. However you should be aware that if you use the mail() function, many delivery errors will be sent to the bogus webserver user and not to you.
Copy linkTweet thisAlerts:
@LanceauthorSep 29.2004 — Thanks NogDog and Yuna for your informative replies. I am off to work now but will look through and try your suggestions. The existing form works fine except that the body of the email that is delivered from the form just shows the field values seperated by a paragraph space whereas I need them to also have a subtitle for each of the form fields. Thanks again.
×

Success!

Help @Lance spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...