Why is my contact form not sending back to my domain - php

Im creating a contact form for my website using Actionscript 3.0 with Flash CS6, I have my code written down perfectly but in order to receive my messages towards my email ain't working :( Here is my code
<?php
$emailTo = "myemail#myemail.com";
$name = $_POST["Patrick"];
$emailFrom = $_POST["myemail#myemail.com"];
$message = $_POST["Hello"];
$subject = "From Contact Form";
if(!empty($_POST)) {
$body = "Name: " . $name . "\n\n";
$body .= "Email: " . $emailFrom . "\n\n";
$body .= "Message:\n" . $message;
$body = wordwrap($body, 70);
$header = "From: " . $emailFrom . "\nReply-To: " . $emailFrom. "\n\n";
if(mail($emailTo, $subject, $body, $header)) {
echo("result=Successful");
} else {
echo("result=Unsuccessful");
}
}
?>
Thanks and hope I you guys can help me

I think the problem lies in how you try to retrieve the $_POST variables.
You're code suggests that you post fields with the names Patrick, myemail#myemail.com and Hello. That wouldn't be logical.
So I guess that your code should be something like the following:
$emailTo = "myemail#myemail.com";
$name = $_POST["name"];
$emailFrom = $_POST["emailFrom"];
$message = $_POST["message"];
$subject = "From Contact Form";
Or for testing purposes (just to see if your mail script is working):
$emailTo = "myemail#myemail.com";
$name = "Patrick";
$emailFrom = "myemail#myemail.com";
$message = "Hello";
$subject = "From Contact Form";

Related

Hi, I am making a contact form thingy, and my php isn't working any reason why?

Error:
the code:
<?php
$name = $_POST['name'];
$mail = $_POST['mail'];
$message = $_POST['message'];
$to ="bejidev27#gmail.com";
$subject = "New contact from " .$name;
$body = "";
$body .= "Name : " .$name. "\r\n";
$body .= "Email : " .$mail. "\r\n";
$body .= $message. "\r\n";
if($mail !=NULL){
mail($to, $subject, $body);
header("Location: index.html") ;
header("Location: done.html") ;
}
?>
It's not sending the mail nor the page is working i need help ,thanks in advance :D
First, check if your servers are running properly. Then, for the following
$name = $_POST['name'];
$mail = $_POST['mail'];
$message = $_POST['message'];
There need to be values for each you. If you are getting the values from a form, then you have to handle the form first using the 'isset' function, to be able to pass the values to each variables.

After form submit Make a alert with Success message PHP

I have a fully working form that sends emails on submit, I would like to have some kind of alert if the email is sent successfully. I saw a lot of solutions with jquery or other libraries but I wanna do it with php
<?php
if(isset($_POST['name']) && $_POST['email'] !='') {
$userName = $_POST['name'];
$lastName = $_POST['surname'];
$email = $_POST['email'];
$phoneNumber = $_POST['phonenumber'];
$messageSubject =$_POST['subject'];
$catalog =$_POST['select_catalog'];
$inputsValue =$_POST['radioSet1'];
$inputsValue2 =$_POST['radioSet2'];
$inputsValue3 =$_POST['radioSet3'];
$inputsValue4 =$_POST['radioSet4'];
$to = "levchegochev#gmail.com";
$body = "";
$body = "Akademija Za dizajn"."\r\n";
$body .= "Ime: ".$userName. "\r\n";
$body .= "Prezime: ".$lastName. "\r\n";
$body .= "Email: ".$email. "\r\n";
$body .= "Telefonski broj:".$phoneNumber."\r\n";
$body .= "Nacin na plakanje: ".$catalog. "\r\n";
$body .= "Opcii: ".$inputsValue. "\r\n".$inputsValue2. "\r\n" .$inputsValue3. "\r\n" .$inputsValue4."\r\n";
mail($to,$messageSubject, $body);
if(mail = true ) {
echo 'test'
}
}
?>
You can write:
if(mail == true ) {
echo '<script>alert("Email send!");</script>';
}
you can try this
if(mail) echo '<script>alert("message")</script>';

Contact form php script sending spam to Gmail

I created a php script (for a contact form) to send emails to my Gmail account.
If I use the sender email in the header ($headers = "From: " . $email;), Gmail reports the received message as spam.
If I don't use the email in the header (e.g. the sender name $headers = "From: " . $name;) the message is not reported as spam.
Do you have any suggestion to let me use the email in the header?
Thanks!
<?php
/* Check if the url field is empty (antispam) */
if ($_POST['leaveblank'] != '' or $_POST['dontchange'] != 'http://') {
$name = $_POST['name'];
$faillink = "xxx.php";
header("Location: $faillink");
} else {
$name = $_POST['name'];
$email = $_POST['email'];
$subject_prefix = "[ContactForm]: ";
$subject = $subject_prefix . $_POST['subject'];
$message = $_POST['message'];
$to = "myemail#gmail.com";
$body = "From: " . $name . "\n";
$body .= "Email: " . $email . "\n";
$body .= "Message: " . $message . "\n";
$headers = "From: " . $email;
$oklink = "yyy.php";
$faillink = "xxx.php";
if ( preg_match( "/[\r\n]/", $name ) || preg_match( "/[\r\n]/", $email ) ) {
header("Location: $faillink");
}
$retmail = mail($to, $subject, $body, $headers);
if ($retmail) {
header("Location: $oklink");
} else {
header("Location: $faillink");
}
}
?>
I solved the issue as Iain suggested so I replaced the mail headers as follows:
$headers = "From: " . "noreplay#mydomain.com" . "\r\n";
$headres .= "Reply-To: " . $email . "\r\n";

PHP script to send contact form to inbox

I have created a contact form and I would like for the details be sent to my inbox once the submit button is clicked. Clicking the submit button opens up a new mail page (see getfreepack.org). I have been advised I need a PHP script. I copied one off the web but no too sure how to use it to my advantage. I would appreciate your help.
$Name= $_REQUEST["Name"];
$Email = $_REQUEST["Email"];
$Phone = $_REQUEST["Phone"];
$JobTitle = $_REQUEST["Jobtitle"];
$KeySkills = $_REQUEST["Keyskills"];
$Attachment = $_REQUEST["Attachment"];
$to = "my email address#mail.com";
$subject = "Contact Form";
$message = "Name: " . $Name $message .= "\Email: " . $Email: $message .= "\n Phone: " . $ Phone;
$message .= "\nSubject: " . $Subject; $message .= "\nCover Letter: " . $CoverLetter;
$message .= "\n Attachment: " . $Attachment; $message .= "\nIP Adress: " . $_SERVER['REMOTE_ADDR'];
$message .= "\nBrowser: " . $_SERVER['HTTP_USER_AGENT'];
$message .= "\n\nMessage: " . $theMessage;
$headers = "From: $theEmail";
$headers .= "\nReply-To: $theEmail";
$sentOk = mail($to,$subject,$message,$headers);
echo "sentOk=" . $sentOk;
A very basic one would be :
<?php
$to = "someone#example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse#example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
If you want to go one step more check out the manual : http://php.net/manual/en/function.mail.php
Cheers
You don't need the php to get a form to send to your email address make the form tag like this:
>>action="mailto:youremailaddress#whatever.com">
Input
Input

JQuery Ajax PHP form submit

I'm using Ajax contact form where my contactform.php is something like this :
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$subject = "Contact Form";
$message .= $_POST['name'] . "\n\r";
$message .= $_POST['email'] . "\n\r";
$message .= $_POST['message'];
mail("your#domain.com", $subject, $message, "From: ".$email);
?>
This form script works perfect But My problem is that, My value for "your#domain.com" is dynamic.. So I modified contactform.php to this :
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$emailto = $qc2_options['qc2_form_heading'];
$subject = "Contact Form";
$message .= $_POST['name'] . "\n\r";
$message .= $_POST['email'] . "\n\r";
$message .= $_POST['message'];
mail($emailto, $subject, $message, "From: ".$email);
?>
But this modified script isn't working.. I do get correct value for $qc2_options['qc2_form_heading']; on echo But this form dosn't work.
Where I'm going wrong ?

Categories