I am writing a wedding website with a basic form to get the guest email address, guest name(s), guest dinner option, the number of children they are bringing, and a requested song they would like played. I then want to take these values and send them via PHP mail function to an email address. Here is what I have so far:
Here is the snippet of my javascript. The variables emailAddr, g1_name, and g1_dinner all have the correct values in them when I log it to the console.
var data = {
email : emailAddr,
g1Name : g1_name,
g1Dinner : g1_dinner
};
$.post("email.php", data, function(){
alert("Email Success");
});
Here is the PHP:
<?php
$to = "test#email.com";
$from = $_POST['email'];
$guestName_1 = $_POST['g1Name'];
$guestDinner_1 = $_POST['g1Dinner'];
$message = "Email: "+$from +"\n\nGuest 1: "+$guestName_1+" - "+$guestDinner_1;
$message = wordwrap($message, 70);
mail($to,"Wedding RSVP",$message);
?>
Here is what is actually getting POST'd:
And here is the email I get from my web host:
So my main question is why is what is getting POST to my PHP file different than I am specifying?
And a follow up, why am I getting emailed a 0 and not the string I set?
And is this the right way to do something like this?
Any help is appreciated! Thanks!
PHP 101: String concatenation uses ., you're using +, which is mathematical addition.
'string' + 'string' => generally "0" or wonky integer as result
'string' . 'string' => 'stringstring'
Related
here's my problem: I have a mailbox where came from 2 types of email:
1) e-mail with plain text
2) email, I think, base64-encoded text / html
I have a simple page in php that goes to read this email box, and prints out an HTML table with some information of each email
I recognize the two types of email from the object of the email, in the first case I have no problems, while in the second i have a problem
i read the "body" of the mail of the first type in this way (and I have no problem, I can print the contents of the email as plain text) :
$id = imap_uid($stream ,$email_id);
$message = imap_qprint(imap_body($stream, $email_id,FT_PEEK));
but in the second case it does not work this way, and I have tried the following
$message = imap_fetchbody($stream,$email_id,"");
$message = imap_fetchbody($stream,$email_id,"0");
$message = imap_fetchbody($stream,$email_id,"1");
$message = imap_fetchbody($stream,$email_id,"1.1");
$message = imap_fetchbody($stream,$email_id,"1.2");
$message = imap_fetchbody($stream,$email_id,"2");
echo "*".base64_decode($message)."*";
echo "*".imap_base64($message)."*";
but I have no result
I apologize but I'm very new to PHP and I am trying to create a very simple form that sends an email back to a user when they enter in their email address. I want the message to include some data from our database. I have been able to create a form that works perfectly as long as I enter in the message manually (like $message = "Hi. How you doing?") but I can't seem to figure out how to incorporate the recordset data. What I was hoping was to use something like...
<?php
$to = $_REQUEST['Email'] ;
$message = '<?php echo $row_rsPersonUser['bio']; ?>'; <<<<<<<<Line 63
$fields = array();
$fields{"Email"} = "Email";
$headers = "From: noreply#domain.ca";
$subject = "Thank you";
mail($to, $subject, $message, $headers);
?>
What I get from this is "Parse error: syntax error, unexpected T_STRING in.... on line 63". I know it's formatted wrong but I don't have a clue why. When I drop the into the body, the info I want does display on the webpage so I know that part is working. Any help would be welcomed.
Thanks
You don't have to use PHP start and end tags inside PHP code itself
$message = '<?php echo $row_rsPersonUser['bio']; ?>'; // this is wrong
^^^^^ ^^
Should be
$message = $row_rsPersonUser['bio'];
Just change the 63rd line like below..
you can't start one <?php block in another <?php block
$message = $row_rsPersonUser['bio'];
If you were to do that it would just print <?php echo… as literals since you can't send php code as a email only html/plan text
$message = '<?php echo $row_rsPersonUser['bio']; ?>';
should be:
$message = $row_rsPersonUser['bio'];
and (I tested the following and it appears the {}'s work but you might want to switch to only []'s for standardization and not sure if you might get in trouble later on?)
FROM: http://us1.php.net/manual/en/language.types.array.php
Note:
Both square brackets and curly braces can be used interchangeably for accessing array elements (e.g. $array[42] and $array{42} will both do the same thing in the example above).
$fields{"Email"} = "Email";
should be:
$fields["Email"] = "Email";
You are already inside the php code, no need to add extra php start and end tags inside the variable name. Similar to how you have used the $to variable, you can use the $message variable.
So use
$message = $row_rsPersonUser['bio'];
and it would work fine.
i'm using ajax contact form, downloaded from: http://youhack.me/2010/07/22/create-a-fancy-contact-form-with-css-3-and-jquery/
Everything works ok except UTF as i can't use cyrilic symbols when submitting.
The php:
$name = $_POST['name']; // contain name of person
$email = $_POST['email']; // Email address of sender
$web = $_POST['web']; // Your website URL
$body = $_POST['text']; // Your message
$receiver = "receiver#domain.com" ; // hardcorde your email address here - This is the email address that all your feedbacks will be sent to
if (!empty($name) & !empty($email) && !empty($body)) {
$body = "Name: {$name}\n\nSubject: {$web}\n\nMessage: {$body}";
$send = mail($receiver, 'Contact from domain.com', $body, "From: {$email}");
if ($send) {
echo 'true'; //if everything is ok,always return true , else ajax submission won't work
}
}
It uses jquery.validationEngine-en for validation.
My html already has "Content-Type" content="text/html; charset=utf-8" in header.
I'm new to php and jquery, so i would appriciate some guidance to make UTF-8 work when submitting.
Thanks :)
Edit: When i try to use cyrilic chars (čšćđ) on a required field i get ajax input error "Please use letters only". If i submit the form with cyrilic chars on a non-required field, i receive and email, all letters show ok except cyrilic, which are like this: Å¡.
Edit 2: When i set the recipient to gmail (webmail), cyrilic chars show up ok, except in one field, where Ajax doesnt let me use them (regex from Reinder answer).
When i set recipient in outlook (local) and submit the form, none of the cyrilic chars don't show up ok, example: ÄĹĄ oÄa ĹĄ ÄŽŠÄÄ
SOLVED Thanks to Reinder for guide and David! Will solve it today :)
having looked at the plugin you're using, I think this has to do with the validation regex inside jquery.validationEngine-en.js
when the validation is set to 'onlyLetter' it will check using
/^[a-zA-Z\ \']+$/
and none of your characters čšćđ are allowed here...
you need to create a language validation javascript for the language you're using and change that regular expression. For example, have a look at this post
The next thing is to check the encoding of your PHP file and your headers.
Place this at the top of your PHP code
header("Content-type: text/html; charset=utf-8");
Check if the values are correctly displayed when just outputting them in PHP, like so:
echo $name;
If they are correctly displayed in the browser and it's just the email that's incorrectly displaying the characters, then you need to pass an encoding header to the email too
example:
$headers = "From: $name <$email>\n";
$headers .= "Content-Type: text/plain; charset=UTF-8\n";
$body = "Name: {$name}\n\nSubject: {$web}\n\nMessage: {$body}";
$send = mail($receiver, 'Contact from domain.com', $body, $headers);
have a look at the mail function on the PHP.NET website
Rather than use the default PHP mail() function, I've found this come in handy when working with Japanese:
http://bitprison.net/php_mail_utf-8_subject_and_message
Hi I am creating a task assignment page, in which after creating the task admin can send a mail to assignee to know the task. I cant use PHP mail function since I cant configure office SMTP mail address. So I am using mailto function.
Issue happens when my Commenst got symbols like " &, ", ' . It will stop executing the remaining part of code
In my mail it just populates the first line. So my comments is getting broken.
Here is my code to mailto function :
';
You put everything into one line which brings you into devils kitchen. Instead put the functionality apart (e.g. first load the data from the database), then process the data (e.g. build the mailbox name, the subject and the body) and then finally create the mail URL.
<?php
# load data from database
$assignee = mysql_result($result, $i, 'assignee');
$comments = mysql_result($result, $i, 'comments');
# process data
$mailbox = sprintf('%s#symantec.com', rawurlencode($assignee));
$headers = array(
'subject' => 'Task Assignment',
'body' => "Hello $assignee,\n\nDescription : $comments ...\n\nFor more details log in to ...",
);
# generate the mailto URL
$url = sprintf('mailto:%s?%s', $mailbox, http_build_query($headers));
You can then just output the $url:
printf('<img src="images/mail.png" width="32" height="32" p="center">',
$url);
You need to explicity urlencode everything that is non alphanumeric.
Note, urlencode (the php command) doesn't urlencode everything such as underscore and letters and perhaps other things.
Example:
$test="this: is it's dog/+_";
echo "<br>";
echo urlencode($test);
echo "<br>";
echo $test;
produces:
this%3A+is+it%27s+dog%2F%2B_
this: is it's dog/+_
I am building a flash website and I want contact information sent to my gmail address.
The Lynda.com tutorial I am using says I need to "enter the php address." What is that and how do I do it?
This is my code edited
if (thename.text == "" || theemail.text == "" || thephone.text == "" || themessage.text =="") {
thefeedback.text = "*Please fill out all fields";
} else {
var allvars:URLVariables = new URLVariables()
allvars.name = thename.text;
allvars.email = theemail.text;
allvars.phone = thephone.text;
allvars.message = themessage.text;
// Send info to a new request
var mailAddress:URLRequest = new URLRequest("http://whatever goes here.php");
mailAddress.data = allvars;
mailAddress.method = URLRequestMethod.POST;
sendToURL(mailAddress);
thefeedback.text = "Thank You";
thename.text = "";
theemail.text = "";
thephone.text = "";
themessage.text = "";
}
Presumably they mean "A URL that resolves to the PHP script that they taught you to write", but "php address" is not a standard term.
When you press submit on any form it is taking that information (first name, last name, body text, etc) and then it needs to be sent somewhere so that it can be given to gmail or anther email service as an actual email.
Now PHP on a server can take the information, turn it into an email, and send it from you to them.
You can do this by using POST and the URL is to a PHP script that lives somewhere.
Now that script needs set up, you can learn how HERE
Good luck friend!
You can use Zend PHP to use PHP functions from Flash.
This tutorial is pretty good: http://www.flepstudio.org/forum/tutorials/3421-actionscript-3-0-zend-amf.html