Error Missing file part Php Google cloud platform POST - php

I'm simply trying to "post" text from a subscribe form to a simple email php file but Google Cloud gives this error:
<Error>
<Code>InvalidArgument</Code>
<Message>Invalid argument.</Message>
<Details>Missing file part</Details>
</Error>
I have tried a few things including writing directly to the bucket in Google Cloud but I would rather have text emailed to an address. Why is there a missing file part?
here is my form code:
<form action="email.php" method="post" enctype="multipart/form-data">
<input type="text" name="email" size="15" style="font-size:29px;" id="email" required placeholder="Email">
<input value="RSVP" class="button" name="button" style="font-size:29px;" type="submit">
</form>
Here is my php file:
<?php
$to = "email#gmail.com"; //
$from = "no-reply#website.com"; //
$headers = "From: " . $from . "rn";
$subject = "New subscription";
$body = "New user subscription: " . $_POST['email'];
if( filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) )
{
if (mail($to, $subject, $body, $headers, "-f " . $from))
{
echo 'Your e-mail (' . $_POST['echo $this->mail'] . ') has been added to our mailing list!';
}
else
{
echo 'There was a problem with your e-mail (' . $_POST['email'] . ')';
}
}
?>

Related

Not getting any email from PHP contact form [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 4 years ago.
So I am creating a simple website and on the "contact us" page I have put a contact form that is supposed to mail the message there. The form actually gives a success message that the email is sent but I'm not getting any. I have checked the spam/junk folder as well. I tested this on apache local server. (My email is correct. I've stated it like that on the code here for privacy issues.)
Can I please have some insight on what I am missing since I am fairly new to coding?
<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Mesazhi u dergua!'
);
$name = #trim(stripslashes($_POST['emri']));
$email = #trim(stripslashes($_POST['email']));
$phoneno = #trim(stripslashes($_POST['telefon']));
$message = #trim(stripslashes($_POST['mesazhi']));
$email_from = $email;
$email_to = 'name.surname#mail.net';
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Phone NO: ' . $phoneno . "\n\n" . 'Message: ' . $message;
$success = #mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
?>
<div class="contact-form">
<form action="sendemail.php" name="contact-form" method="post">
<input type="text" name="emri" placeholder="Emri" />
<input type="email" name="email" placeholder="Email" />
<input type="tel" name="telefon" placeholder="Nr Telefoni"/>
<textarea name="text" id="text" rows="8" placeholder="Teksti" name="mesazhi"></textarea>
<input type="submit" class="btn-send" value="Dergo">
</form>
</div>
Use this code mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
you are using a # on each function call. Remove them and you will maybe see where the problem is.

Issue with simple PHP Contactform

So I have some issues with my PHP Contactform on a HTML site.
Code below is what I have written in HTML. (that's not te problem)
<form action="sendmail.php" method="POST" class="contact-form">
<input type="text" placeholder="Amount" name="amount">
<input type="text" placeholder="Name" required name="name">
<input type="text" placeholder="Email Address" required name="email">
<div class="validation">
<button class="btn" name="submit">Send request</button>
// END HTML code. (BELOW is starts PHP).
$email_to = "domain#website.com";
$amount = $_POST["amount"];
$name = $_POST["name"];
$email = $_POST["email"];
$email_subject = "DOMAINNAME";
$headers = "From: " . $email . "\n";
$headers .= "Reply-To: " . $email . "\n";
$message = 'Name: ' . $name . ', email: ' . $email . ', amount: ' . $amount;
ini_set("sendmail", $email);
if (!filter_var($email, FILTER_VALIDATE_EMAIL) === false)
{$sent = mail($email_to, $email_subject, $message, $headers, "-f" .$email);}
{
header("Location:https://website.com");
} else {
echo "There has been an error sending your comments. Please try later.";
}
What do I wrong? I only wanna receive the --> name, amount and mail.
Only when I press submit on my HTML site, it's send me to website.com/sendmail.php (HTTP ERROR 500).
Thank you guys.

Simple subscriber email form - PHP/HTML [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I am trying to create a simples subscriber email form , where one user inserts his email, and me and the client should receive a e-mail.
Email to me saying that got a new subscription.
Email to client saying that we will contact him shortly.
I know very little about php, i ask for help about what is wrong on this code and how to make it better in order to make what i want.
HTML:
<div class="mail2">
<!-- Subscription Form -->
<form action="form/form.php" method="post">
<h1>Try Now!</h1>
<input name="email" class="email" type="text" placeholder="Enter your email address ...">
Get started for free
<a class="top" href="#top">Top</a>
</form>
</div>
PHP:
<?php
$to = "office#site.com";
$from = "no-reply#site.com";
$headers = "From: " . $from . "\r\n";
$subject = "New subscription";
$body = "New user subscription: " . $_POST['email'];
if( filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) )
{
if (mail($to, $subject, $body, $headers, "-f " . $from))
{
echo 'Your e-mail (' . $_POST['email'] . ') has been added to our mailing list!';
}
else
{
echo 'There was a problem with your e-mail (' . $_POST['email'] . ')';
}
}
else
{
echo 'There was a problem with your e-mail (' . $_POST['email'] . ')';
}
Edit your html code..
<div class="mail2">
<!-- Subscription Form -->
<form action="form/form.php" method="post">
<h1>Try Now!</h1>
<input name="email" class="email" type="text" placeholder="Enter your email address ...">
<input type="submit" value="Get started for free">
<a class="top" href="#top">Top</a>
</form>
</div>
I would have to say first your HTML has an issue. With the Get started now. You're not actually submitting the form, you're just linking back to the page you're on.
So first change the HTML:
<div class="mail2">
<!-- Subscription Form -->
<form action="form/form.php" method="post">
<h1>Try Now!</h1>
<input name="email" class="email" type="text" placeholder="Enter your email address ...">
Get started for free
<a class="top" href="#top">Top</a>
</form>
</div>
Secondly, here's a neater version of the PHP with some improvements.
$to = "office#site.com";
$from = "no-reply#site.com";
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: " . $from;
$headers[] = "Reply-To: " . $from;
$headers[] = "X-Mailer: PHP/".phpversion();
$subject = "New subscription";
$body = "New user subscription: " . $_POST['email'];
if( filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) )
{
if (mail($to, $subject, $body, implode("\r\n", $headers)))
{
echo 'Your e-mail (' . $_POST['email'] . ') has been added to our mailing list!';
}
else
{
echo 'There was a problem with your e-mail (' . $_POST['email'] . ')';
}
}
else
{
echo 'There was a problem with your e-mail (' . $_POST['email'] . ')';
}
If the rest doesn't work, make sure that sendmail is installed and setup correctly on the server.
Just to point out that if the mail check returns false it might not specifically be the e-mail that's at fault as your output error message suggests.

PHP mail form is not working

I m having a problem with my email php form, when I click in the submit button an other page shows up saying There was a problem with your e-mail ()
I don't no what I am doing wrong?
here is my code:
html code
<!-- Subscription Form -->
<form class="email" action="form.php" method="post">
<input class="get_notified" type="text" placeholder="Enter your email address ..."/>
<button type="submit" class="go" /></form>
<!-- End Subscription Form -->
</div>
</div>
</body>
php code
<?php
$to = "email#mydomain.com";
$from = "email#mydomain.com";
$headers = "From: " . $from . "\r\n";
$subject = "New subscription";
$body = "New user subscription: " . $_POST['email'];
if( filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) )
{
if (mail($to, $subject, $body, $headers, "-f " . $from))
{
echo 'Your e-mail (' . $_POST['email'] . ') has been added to our mailing list!';
}
else
{
echo 'There was a problem with your e-mail (' . $_POST['email'] . ')';
}
}
else
{
echo 'There was a problem with your e-mail (' . $_POST['email'] . ')';
}
You'll need to add a name="email" field to your HTML form in order for PHP to be able to fetch it using $_POST['email']
<input class="get_notified" name="email" type="text" placeholder="Enter your email address ..."/>

Need some help with a HTML form PHP send email combo platter

PHP has never been my strong suit so I need some assistance getting the contents of a form to send via email properly in PHP.
Here is the html form:
<form action="estimate.php" method="post" >
<fieldset>
<input type="text" class="required" name="name" value="FULL NAME*" onfocus="if (this.value=='FULL NAME*') this.value='';"/>
<input type="text" class="required" name="phone" value="PHONE NUMBER*" onfocus="if (this.value=='PHONE NUMBER*') this.value='';"/>
<input type="text" class="required" name="email" value="EMAIL*" onfocus="if (this.value=='EMAIL*') this.value='';"/>
<input type="text" class="required" name="date" value="MOVE DATE*" onfocus="if (this.value=='MOVE DATE*') this.value='';"/>
<input type="text" class="required" name="origin" value="ORIGINATING ADDRESS*" onfocus="if (this.value=='ORIGINATING ADDRESS*') this.value='';"/>
<input type="text" name="destination" value="DESTINATION ADDRESS" onfocus="if (this.value=='DESTINATION ADDRESS') this.value='';"/>
<select name="move-type">
<option value="" selected="selected">TYPE OF MOVE</option>
<option value="Private">Private</option>
<option value="Commercial">Commercial</option>
</select>
<input id="quoteSubmit"
type="image" src="_images/btn_submit.png" alt=""
onmouseover="javascript:this.src='_images/btn_submit-over.png'"
onmouseout="javascript:this.src='_images/btn_submit.png'"/>
</fieldset>
</form>
Here is the PHP I have thus far:
<?php
$emailFromName = $_POST['name'];
$emailFromPhone = $_POST['phone'];
$emailFrom = $_POST['email'];
$emailDate = $_POST['date'];
$emailOrigin = $_POST['origin'];
$emailDestination = $_POST['destination'];
$emailType = $_POST['move-type'];
if (empty($emailFromName)) {
echo 'Please enter your name.';
} elseif (!preg_match('/^([A-Z0-9\.\-_]+)#([A-Z0-9\.\-_]+)?([\.]{1})([A-Z]{2,6})$/i', $emailFrom) || empty($emailFrom)) {
echo 'The email address entered is invalid.';
} elseif (empty($emailDate)) {
echo 'You must enter a Move date.';
} elseif (empty($emailOrigin)) {
echo 'You must enter a message.';
} elseif (empty($emailDestination)) {
echo 'You must enter a message.';
} else {
$emailTo = "info#movingsimple.com";
if (!empty($emailFrom)) {
$emailHeaders = 'From: "' . $emailFromName . '" <' . $emailFrom . '>';
} else {
$emailHeaders = 'From: "The Boss" <noreply#movingsimple.com>';
}
/* Send Email */
if (mail($emailTo, $emailSubject, $emailDate, $emailHeaders)) {
echo 'Thank you! Your message has been sent.';
} else {
echo 'There was an internal error while sending your email.<br>';
echo 'Please try again later.';
}
}
?>
I am having trouble with the body of the message. I need to display all the values from the form:
From:
Email:
Phone:
Move date:
Origin:
Destination:
Move type:
but I am not exactly sure how to compile all those into the body and would appreciate some help.
thanks.
Update this part of the code
if (!empty($emailFrom)) {
$emailHeaders = 'From: "' . $emailFromName . '" <' . $emailFrom . '>';
} else {
$emailHeaders = 'From: "The Boss" <noreply#movingsimple.com>';
}
/* Send Email */
if (mail($emailTo, $emailSubject, $emailDate, $emailHeaders)) {
echo 'Thank you! Your message has been sent.';
to generate a string containing the body of the email:
if (!empty($emailFrom)) {
$emailHeaders = 'From: "' . $emailFromName . '" <' . $emailFrom . '>';
} else {
$emailHeaders = 'From: "The Boss" <noreply#movingsimple.com>';
}
// Create a string representing the body. "\n" creates a new line.
// The ".=" operator appends the string onto the existing string.
$body = "From: ".$emailFromName."\n";
$body .= "Email: ".$emailFrom."\n";
$body .= "Phone: ".$emailFromPhone."\n";
$body .= "Move Date: ".$emailDate."\n";
$body .= "Origin: ".$emailOrigin."\n";
$body .= "Destination: ".$emailDestination."\n";
$body .= "Move Type: ".$emailType."\n";
/* Send Email */
if (mail($emailTo, $emailSubject, $body, $emailHeaders)) {
echo 'Thank you! Your message has been sent.';
// ... rest of the code ...
The third parameter of the mail() function (http://us.php.net/manual/en/function.mail.php) is the message, so we create the message as a string ($body) and then pass it as a parameter to the mail() function.
Small Update: The PHP mail() help page says to use "\n" as a line ending rather than "\r\n"
The third attribute to the mail function is for body of the email not date like you are specifying $emailDate, you should specify the email body there.
Right now you're sending the $emailDate as the body of the message.. You just need to build a variable with the data you want. i.e.
$emailBody = "Move date: " . $emailDate;
I think your header variable needs to have a \r\n at the end, too.

Categories