Copy link to clipboard
Copied
Hello,
I am designing a form.
Here is the link:
http://www.simplecelebrations.info/contact3.php
For the most part it works. Except for the self generated email function with the little bit of php script I've added.
<?php
$to = "thomas@reelcreative.tv";
$subject = $_POST['subject'];
$body = $_POST['comments'];
$headers = "From:relay-hosting.secureserver.net " . $_POST['emailAddress'] . "\n";
$mailSent = mail($to,$subject,$body,$headers);
?>
This script works. Except I want to add more information from the self generated email.. I want all the information from the form to display in the email I'd receive when a form is submitted.
It seems like there are a maximum of 5 parameters allowed. Is that correct? It doesn't seem right? -But why if I add an additional parameter like 'emailAddress' I get a line of code that shows:
<?php
$to = "thomas@reelcreative.tv";
$subject = $_POST['subject'];
$body = $_POST['comments'];
$headers = "From:relay-hosting.secureserver.net " . $_POST['emailAddress'] . "\n";
$emailAddress= $_POST['emailAddress'];
$mailSent = mail($to,$subject,$body,$emailAddress,$headers);
?>
/home/content/r/e/e/reelcompanies/dead.letter... Saved message in /home/content/r/e/e/reelcompanies/dead.letter
I've no idea where this error comes from? I gist know it the straw that breaks the Camel's back. Because when I remove this one additional parameter this line of code which shouldn't be, goes away.
How can I make my PHP code display all the fields from my form?
I've tried:
<?php
if (array_key_exists('***FormButton***', $_POST)) {
$to = 'mailto:thomas@reelcreative.tv';
$subject = $_POST['subject'];
$body = $_POST['comments'];
$headers = "From:relay-hosting.secureserver.net " . $_POST['emailAddress'] . "\n";
$mailSent = mail($to,$subject,$body,$headers);
}
?>
Which works - except when I add the 6th parameter to be displayed?
Actually correction - It works but I gee the line of code:
/home/content/r/e/e/reelcompanies/dead.letter... Saved message in /home/content/r/e/e/reelcompanies/dead.letter
Or something similar? - What is this how do I make it go away?
Thank you!
Copy link to clipboard
Copied
thomastables wrote:
This script works. Except I want to add more information from the self generated email.. I want all the information from the form to display in the email I'd receive when a form is submitted.
It seems like there are a maximum of 5 parameters allowed. Is that correct? It doesn't seem right?
Yes, it's right. You can't just add extra parameters to a PHP function and expect it to work. The syntax for mail is as follows:
mail($to, $subject, $message, $headers, $additional_params);
The first three are required. The last two are optional. The whole body of the message must go in the third parameter as a single string.
So, there's your answer: combine all the form fields into a single string, using the combined concatenation operator:
$message = 'Name: '. $_POST['name'] . "\n";
$message .= 'Address: ' . $_POST['address'] . "\n";
$message .= 'Comments: ' . $POST['comments'];
By the way, putting the email address directly in the headers, as you are doing, is extremely insecure. You should filter it first, to make sure it's not attempting to inject spoof headers into your email and turn your form into a spam relay. If you are using PHP 5, you can do it like this:
if (filter_input(INPUT_POST, 'emailAddress', FILTER_VALIDATE_EMAIL)) {
$headers = 'From: ' . $_POST['emailAddress'];
} else {
$headers = null;
}
Copy link to clipboard
Copied
Hi Thanks for your answer.
Here is what I still don' get.
This script works for me:
<?php
$to = "thomas@reelcreative.tv";
$subject = $_POST['subject'];
$body =
$_POST['comments'];
$headers = "From:relay-hosting.secureserver.net " .
$_POST['emailAddress'] . "\n";
$mailSent =
mail($to,$subject,$body,$headers);
mail($to, $subject, $message, $headers,
$additional_params);
?>
As soon as I try to add the code below for security I get an error:
if (filter_input(INPUT_POST, 'emailAddress', FILTER_VALIDATE_EMAIL)) {
$headers = 'From: ' . $_POST['emailAddress'];
} else {
$headers = null;
}
Where or how can I implement this code?
I am sorry I don;t have much experience other than what I am reading.
And many times there seems to be more than one way to do something.
Which is great if you know how.
Thanks in advance for your patience.
I still have a few more questions. I thought attempting to add this IF
statement would be a good place to start.
Copy link to clipboard
Copied
Hello,
I just wanted to Thank You.
The form works per your suggestions.
All the information is showing in the generated email.
I seriously don't how to immplement the filter.
Here is my current Code:
How and where do input the code the filter you mnetioned?
<?php
$to = "thomas@reelcreative.tv";
$subject =
$_POST['subject'];
$message .= 'firstName: ' . $_POST['firstName'] .
"\n";
$message .= 'lastName: '. $_POST['lastName'] . "\n";
$message .=
'emailAddress: ' . $_POST['emailAddress'] . "\n";
$message .= 'phoneNumber:
' . $_POST['phoneNumber'] . "\n";
$message .= 'newCustomer: ' .
$_POST['newCustomer'] . "\n";
$message .= 'Online: ' . $_POST['Online'] .
"\n";
$message .= 'instore: ' . $_POST['instore'] . "\n";
$message .=
'myspace: ' . $_POST['myspace'] . "\n";
$message .= 'facebook: ' .
$_POST['facebook'] . "\n";
$message .= 'twitter: ' . $_POST['twitter'] .
"\n";
$message .= 'referral: ' . $_POST['referral'] . "\n";
$message .=
'eventdescription: ' . $_POST['eventdescription'] . "\n";
$message .=
'Venue: ' . $_POST['Venue'] . "\n";
$message .= 'eventservices: ' .
$_POST['eventservices'] . "\n";
$message .= 'dancers: ' . $_POST['dancers']
. "\n";
$message .= 'models: ' . $_POST['models'] . "\n";
$message .=
'photog: ' . $_POST['photog'] . "\n";
$message .= 'guests: ' .
$_POST['guests'] . "\n";
$message .= 'duration: ' . $_POST['duration'] .
"\n";
$message .= 'comments: ' . $_POST['comments'] . "\n";
$headers =
"From:relay-hosting.secureserver.net " . $_POST['emailAddress'] .
"\n";
$mailSent = mail($to,$subject,$message,$headers);
?>
Thank You very much
Copy link to clipboard
Copied
make your life simple. take a look at the following extensions:
php mail: http://cmiwebstudio.com/adobe_extensions/dreamweaver_easy_php_mailer
php mail with pear mail and mail mime: http://cmiwebstudio.com/adobe_extensions/dreamweaver_easy_php_mailer_pear
it automates the entire thing. simply fill in the mail server information, and it does the rest, emailing all of your form fields (no matter how many or what types).
Copy link to clipboard
Copied
thomastables wrote:
I seriously don't how to immplement the filter.
Here is my current Code:
How and where do input the code the filter you mnetioned?
It replaces the following code:
$headers = "From:relay-hosting.secureserver.net " . $_POST['emailAddress'] . "\n";
Copy link to clipboard
Copied
Hey thanks but, everytim I replace :
$headers = "From:relay-hosting.secureserver.net " . $_POST['emailAddress'] . "\n";
with:
if (filter_input(INPUT_POST, 'emailAddress', FILTER_VALIDATE_EMAIL)) {
$headers = 'From: ' . $_POST['emailAddress'];
} else {
$headers = null;
}I get a fatal error message.
Here is my code:
<?php
$to = "events@simplecelebrations.info";
$subject = $_POST['subject'];
$message .= 'firstName: ' . $_POST['firstName'] . "\n";
$message .= 'lastName: '. $_POST['lastName'] . "\n";
$message .= 'emailAddress: ' . $_POST['emailAddress'] . "\n";
$message .= 'phoneNumber: ' . $_POST['phoneNumber'] . "\n";
$message .= 'newCustomer: ' . $_POST['newCustomer'] . "\n";
$message .= 'Online: ' . $_POST['Online'] . "\n";
$message .= 'instore: ' . $_POST['instore'] . "\n";
$message .= 'myspace: ' . $_POST['myspace'] . "\n";
$message .= 'facebook: ' . $_POST['facebook'] . "\n";
$message .= 'twitter: ' . $_POST['twitter'] . "\n";
$message .= 'referral: ' . $_POST['referral'] . "\n";
$message .= 'eventdescription: ' . $_POST['eventdescription'] . "\n";
$message .= 'Venue: ' . $_POST['Venue'] . "\n";
$message .= 'eventservices: ' . $_POST['eventservices'] . "\n";
$message .= 'dancers: ' . $_POST['dancers'] . "\n";
$message .= 'models: ' . $_POST['models'] . "\n";
$message .= 'photog: ' . $_POST['photog'] . "\n";
$message .= 'guests: ' . $_POST['guests'] . "\n";
$message .= 'duration: ' . $_POST['duration'] . "\n";
$message .= 'comments: ' . $_POST['comments'] . "\n";
$headers = "From:relay-hosting.secureserver.net " . $_POST['emailAddress'] . "\n";
$mailSent = mail($to,$subject,$message,$headers);
if (filter_input(INPUT_POST, 'emailAddress', FILTER_VALIDATE_EMAIL)) {
$headers = 'From: ' . $_POST['emailAddress'];
} else {
$headers = null;
}Copy link to clipboard
Copied
use the @
e.g.
@mail($to, $subject, $message, $headers, $additional_params);
it stands for hide the mistake for users!
So eg. if ypur inputs not fill hin, any brwoser can show the user "you dont fill in ...."
and @ avoid it.
you also should work with tables in your code like
<tr>
<td>Name:</td><td><input type="text" name="name" value="<?php
if (isset($_POST['name']))
{
echo htmlspecialchars(stripslashes($_POST['name']));
}
?>">
</td>
</tr>
hope it helps you fairly
Find more inspiration, events, and resources on the new Adobe Community
Explore Now