This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 8 years ago.
For some reason My PHP email form does not send the html form data, the headings are there, but the imputed data is not however when the files are put on the development server, a sub domain of the main website 123.123.com, the email sends with the form data, with no issue at all.
It seems to do this on all the forms on the website, could this be server related? or am I missing something. any help would be appreciated.
<?php
mail( "Test#test.con, "Interlinks Sign Up",
"\nName: - $fulllname
\nEmail:- $email
\nContact Number: - $contactnumber
\nCountry:- $country
\nTown/City:- $city
\nPost Code:- $postcode
\nAbout Yourself: - $about
\nWork And Business: - $work
\nJob Description: - $job
\nIndustry Description: - $industry
\nWebsite: - $website
\nLanguage: - $language
\nWho To Meet:- $meet
\nAgree: - $agree ",
"From: blank#test.com" );
?>
In order to get the data from your HTML form you will need to use $_POST['form_element_name_here'] or $_GET['form_element_name_here'] depending on the type of form action that you used. If you are already doing thing and are binding these to the variables that you are using in your original code we will need to have a look at the entire PHP script and HTML front end that is processing the form.
Related
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed last year.
I have been trying to build my own website and a central part of it is a form. I have set up an email address to recieve form results. I have been able to run the website on localhost and everything but the forms are working. When I click submit, it sucsessfully sends me to the PHP file and I am not recieving any emails from the file. I have checked my spam and it is empty. I am brand new to PHP and I tried to adapt some code I found online. I am not sure if there is anything wrong with my code or not. If anyone could help that would be great. I am also trying to be able to send an image file through the form. This is a screenshot of what the server log says when I try to submit the form. Server Log Screenshot
This is the code I have wrote:
<?php
$title = htmlspecialchars($_POST['title']);
$coordinates = htmlspecialchars($_POST['coordinates']);
$description = htmlspecialchars($_POST['description']);
$shelterorcampsite = htmlspecialchars($_POST['shelter-campsite']);
$distanceToWater = htmlspecialchars($_POST['howfarawayiswater']);
$image = $_POST['file'];
$email_from = 'contactbackpackingproject#gmail.com';
$email_subject = "New Form submission";
$email_body = "There has been a new campsite submission.
The title is: $title;
The type is: $shelterorcampsite;
The coordinates are: $coordinates;
The description is: $description;
The distance to water is: $distanceToWater;
An image is: $image";
$to = 'contactbackpackingproject#gmail.com';
mail($to,$email_subject,$email_body,$headers);
?>
This is a screenshot of the code is VS code: VS code screenshot
Often it's helpful to find the exact error message that is triggered by the mail() function. While the function doesn't provide an error directly, you can use error_get_last() when mail() returns false.
<?php
$success = mail('example#example.com', 'My Subject', $message);
if (!$success) {
$errorMessage = error_get_last()['message'];
}
?>
Please identify the errors as without them nobody can help you and the log that you provided is just a POST request which doesn't necessarily indicate that mail function executed successfully.
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 2 years ago.
I am trying to send a basic confirmation email after a user submits my html form using the php mail() function, but for some reason the email won't send. Here is my code:
<?php
echo "You're all set! You should be recieving a confirmation email within the next few minutes.";
$to = $_POST["email"];
$subject = "Your Appointment";
$msg = "Your appointment has been scheduled for " . $_POST["ApptDate"] . ".";
mail($to,$subject,$msg);
?>
I know my form is working correctly, because I am taken to this page after I submit the form. Also, "email" and "ApptDate" are keys I stored in my html form, and when I echo the variables they all print, so I don't think its a variable related error. Any help would be greatly appreciated.
is it localhost? or a server?
You would need an SMTP server setup in either case,
For localhost i use this one as its a one-click-never-touch-again setup
https://toolheap.com/test-mail-server-tool/users-manual.html
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 3 years ago.
So I'm learning my way through PHP and I followed a tutorial exactly for creating a form that uses php to send me an email through the server I'm using but its not working. I checked around to see if my question has been answered in a way I can understand but I came up empty. I probably just don't know enough about this language but I want to get this feature up and running at least so I can have a way to receive emails without giving out mine. please don't suggest other options I want to fix this code.
I have checked to make sure I followed the tutorial correctly and I have. I am missing something key here I just don't know what.
<?php
if (ifset()$_POST['submit']) {
$name = $_POST['name'];
$subject = $_POST['subject'];
$mailFrom = $_POST['mail'];
$message = $_POST['message'];
$mailTo = "https://formspree.io/xoqaovaa"
$headers = "From: ".$mailFrom;
$txt = "you have recieved an E-mail from ".$name.".\n\n".$message;
mail($mailTo, $subject, $txt, $headers);
header("Location: contactForm.php?mailsend");
}
?>
I expected my contact form to accept inputs from the user in various fields and send those in a message though my server to my email routing service when the user clicks submit button.
what happens when I go to the page is this error: Parse error: syntax error, unexpected '$_POST' (T_VARIABLE) in /storage/ssd5/051/11462051/public_html/PHP/master.php on line 2
The name of the function is isset(), not ifset(). And you have the ) in the wrong place. It should be:
if (isset($_POST['submit'])) {
And then you are missing the terminating ; at this line:
$mailTo = "https://formspree.io/xoqaovaa"
This question already has answers here:
Reading JSON POST using PHP
(3 answers)
Closed 7 years ago.
I want to send json payload to my PHP webservice. I am testing on advance rest client. I already search similar answers. But it is not helping me.
I am sending this json to my php service which is running on localhost.
{
"name":"XXXX",
"password":"YYYYY"
}
I changed the content-type from dropdown to application/json.
However sending value as form parameter from advance rest client works fine.But this is not what i want.
My php code is
$name= isset($_POST['name']) ? mysql_real_escape_string($_POST['name']) : "";
$pass= isset($_POST['pass']) ? mysql_real_escape_string($_POST['pass']) : "";
echo $name;
echo $pass;
but it is always printing the blank value.
I am new to php but found this is the way to receive post params.
I found the solution if any one else facing same issue. To read the json data sent in the request body we can use this method
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$request_body = file_get_contents('php://input');
$data = json_decode($request_body);
$name = isset($data->name) ? mysql_real_escape_string($data->name) : "";
echo $name
}
Now it will give the correct value.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
To preface, I am sorry for asking what is likely an extremely simple question. I am an intern for a non-profit helping with some web tasks and have been asked to build a submission form. I want the data inputted in the fields to send to my email address. The form code is fine, however it is the PHP script that seems to not be working. Can anyone suggest a simple PHP code (or another method) to parse this info a designated email address? Currently using method="post"
Here is the form code: http://pastebin.com/7Gxb92n5
Thank you!
Alex
Your form uses the method POST, so in send_form_application.php you will have to use the mail() function.
Name [Last, First MI] <input type="text" name="name" /><br />
Primary Organization <input type="text" name="primary_organization" /><br />
This above is your HTML that will POST variables contained in a $_POST array.
So $_POST['name'] will contain you name and
$_POST['primary_organization'] will contain the primary organization (what the user made as an input in the form)
The "most important part" of this HTML input is the name because it is what you will use to "fill" the mail function with it's attributes.
Your PHP will look something like:
mail($to, $subject, $message, $headers);
?>
The $content could be all the elements of the post like this (should actually be above the previous code)
$content = $_POST['name'] . "\n";
$content .= $_POST['primary_organization'] . "\n";
?>
And so on...
Please tell me if you cant understand something!
IMPORTANT: while this might work, this is not really secure yet, you should ALWASY validate the user input!
On the .php page handling the post ("send_form_application.php" in your case),handle all incoming form fields in the following way:
1) Create variables to store each of your incoming form fields...
...
$name = $_POST["name"]
$primary_org = $_POST["primary_organization"]
$primary_pos = $_POST["primary_position"]
..
ETC...
2) Create an email body string variable to hold all these values however you want to...
3) Then use php's mail functionality to email the info to yourself...
More info here-> http://php.net/manual/en/function.mail.php
Hope that helps!
To verify your server/mail configuration is okay, try the simplest possible code:
<?php
mail("info#nonprofit.org", "form info", print_r($_POST, TRUE));
And you could assemble the body much easier like this (note that clean_string makes no sense for the email body):
$email_message = <<<END
Name [Last, First MI] : $_POST["name..."]
Primary Organization : $_POST["org..."]
Street Address : $_POST["street..."]
City : $_POST["city..."]
State : $_POST["state..."]
END;
Well here is a script that should give you the basic Idea on how to send an email via PHP
http://email.about.com/od/emailprogrammingtips/qt/How_to_Send_Email_from_a_PHP_Script.htm
But other than that your html looks fine...