PDA

View Full Version : PHP query


BOAC
28th Oct 2010, 11:09
I have a php mailer form on a site. I would like to return the following contents of the incoming email in a php generated email reply with additional text added.

$fields{"Name"} = "Name";
$fields{"Email"} = "Email";
$fields{"Phone"} = "Phone";
$fields{"Message"} = "Booking Request";

Any gurus on line? Google seems devoid of help here.

tailstrikecharles
28th Oct 2010, 23:05
So.. I'll take a guess, and answer that

You have a php form. Lets say that you have something you rent, they go online, fill out the form, and when they click submit, you then get an email with their information and request



Name [________]
Email [_________]
Phone [_______]

Booking Request
[___________________________]
[____________________________]
[____________________________]


^That is how the form would probably look


The HTML of the form would have..

<html>
<head>
</head>
<body>
<form target="mailer.php" action="post">
....etc..
</form>
</body>
</html>



Mailer PHP will be basically your form letter

Generally, what is best to do is have the actual letter (that gets the text replaced) as a separate file altogether, and included at run-time, but for this explanation we have it all in one.

Note that this simple explanation does not have the added protections you need to have (to prevent spamming, hacking and assholes)

<?php
// note.. the fields in the form will show up here as variables in the $_POST object as follows
$name = $_POST['name']; //etc etc

//email template
$headers = "From:". $_POST['email']."\r\n"
$subject="Booking request";
$to ="[email protected]";
$body = $_POST['request'];

if (@mail($to, $subject, $body, $headers)) {
echo("<p>Message sent!</p><pre>" .$body. '</pre>');
} else {
echo("<p>Message delivery failed...</p>");
}

BOAC
29th Oct 2010, 08:00
TSC - thanks for replying, but I am confused! How does that return the incoming email from the mailer as a reply with text added to the sender?

PS Not too bothered about 'spamming, hacking and assholes' as the email will not go to me:)

tailstrikecharles
29th Oct 2010, 12:32
How does the process work now?

As far as the 'incoming email' bit, there is no "email" - not really, there is a form on a web page, the user inputs some info to the form, and clicks SUBMIT. then it goes to another page which 'sees' the info that was on the page and concatenates it into text which it then emails out

example
(Previous page had fields, sex, phone, email, firstname)

$title ="Mr. " ;
$recommend_vehicle ="Ford Mustang";
$recommend_vehicle="Volkswaggon Beetle";

if ($sex="F" ) {
$title ="Ms. ";

email_message$ ="Dear ". $title. $firstname . ", how are you today? ";
email_message$ .="I have just the car for you! ";

email_message$ .="You will love your new " . $recommend_vehicle;
email_message$ .=" we will call " .$number. " to arrange delivery ";

...sendmail...



Now, if you have an email address that is already receiving emails, and you want to open them up, "read" them, and send some intelligent email back, thats a bit more complicated, and will depend on the email system you are reading from and need SMTP/IMAP information.

I dont believe your situation is that complicated however..

pm me a link to the page and I'll give it a look, its often more difficult to' explain than show

BOAC
29th Oct 2010, 14:05
PM on the way.

tailstrikecharles
29th Oct 2010, 18:23
It is exactly as I said above.

You are not actually getting an 'incoming email' you are getting the submitted values of a form.
These values you will use to compose an email message that is then sent to the email address the user has specified.

I'll put it up on a demo server as soon as I get off base.

tailstrikecharles
30th Oct 2010, 18:14
wasnt much needed doing either.. formatted the code making it easier to read, changed the variable names to make it easier to follow and added some comments

BOAC
30th Oct 2010, 19:23
Thank you Doctor - feeling better already!