I set up a simple php contact form. It is working so far, I get the emails, that is not the issue. The only thing that is not working, is the "From" and "Reply-To" field. The email I receive is from www-data#hostname.com and it also replies to that address. I don't know what I might have overlooked :(
<?php
$vorname = $_POST['vorname'];
$nachname = $_POST['nachname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$club = $_POST['club'];
$handicap = $_POST['handicap'];
$spieler = $_POST['spieler'];
$bemerkungen = $_POST['bemerkungen'];
$from = 'Von: Kontaktformular';
$to = 'edited for this question';
$subject = 'Anmeldung';
$body = "Von: $vorname $nachname\n E-Mail: $email\n Telefon: $phone\n Club: $club\n Handicap: $handicap\n Spieler: $spieler\n Bemerkung: $bemerkungen ";
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "From: $email" . "\r\n" .
"Reply-To: $email" . "\r\n" .
"X-Mailer: PHP/" . phpversion();
if(!isset($_POST['submit'])) {
if (mail ($to, $subject, $body, $from)) {
header("Location: edited.html");
} else {
header("Location: edited.html");
}
}
?>
Thanks for any hint!
Looks like $headers is not being used in your mail function.
Related
This has to be a simple and stupid question but cant seem to figure it out.
What I want to do is something like:
$message = include ('./myfile.php');
Obviously such does not work, but is there a way to accomplish this if that code worked.
Thanx
Here is full code (abbreviated):
require_once ('./connect.php');
$db = mysqli_connect($db_hostname,$db_username,$db_password,"paratb_members");
$result = mysqli_query($db,"SELECT * FROM board where accesskey = 'CHHXN5Jdwu'");
while ($row = mysqli_fetch_array($result)) {
extract($row);
$message = include './questions/resignation.php';
$subject = "IAP Ballot";
$headers = "From: xxxx" . "\r\n";
$headers .= "Reply-To: xxxx" . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$fromEmail = "xxxx";
$fifth = "-f" . $fromEmail;
$to = "$fname $lname <$email>";
mail($to, $subject, $message, $headers, $fifth);
echo "Email sent to $lname: $email<br>";
You can first read file & store data in variable which contain file's data then you can use that variable.
fopen("myfile.php", "r");
$lines = file("myfile.php");
$message = '';
foreach($lines as $value) {
$message .= $value." ";
}
echo ($message);
I am using this basic php code to send out a html email.
When i use email#email.com as a to address the script works.
However, when i try to use email.2015#gmail.com the script says:
Parse error: syntax error, unexpected '#' in /home/u925912002/public_html/send_email.php on line 3
My code:
<?php
$to = ‘email.2015#gmail.com’;
$subject = 'I need to show html';
$from ='example#example.com';
$body = '<p style=color:red;>This text should be red</p>';
ini_set("sendmail_from", $from);
$headers = "From: " . $from . "\r\nReply-To: " . $from . "";
$headers .= "Content-type: text/html\r\n";
if (mail($to, $subject, $body, $headers)) {
echo("<p>Sent</p>");
} else {
echo("<p>Error...</p>");
}
?>
please can someone show me what i'm doing wrong. thanks
For your question recently closed: https://stackoverflow.com/questions/34106770/send-email-using-php-from-address-not-working
Try this:
$headers .= "From: Your Name <$from>\r\n";
and you can also add the 5th mail parameter:
mail($to, $subject, $body, $headers, '-finfo#userforum.com').
Works for me with these headers:
$from = "$name <$email>\r\n";
$to = "$username <$useremail>\r\n";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= "From: $name <$email>\r\n";
$headers .= "Reply-To: $name <$email>\r\n";
you are using Apostrophe(‘) instead of quotes(')
try this -
$to = 'email.2015#gmail.com';
instead of this -
$to = ‘email.2015#gmail.com’;
I am having problems with this contact page, emails are being sent fine but are blank! I cant seem to find a solution. I would of thought $_POST would need to be added, however, the web hosting companies says it is not necessary in this php script Thankyou for your time and help. Code snippet below.
<?php
$EmailFrom = "sales#ibdengland.co.uk";
$EmailTo = "kent.collins.uk#gmail.com";
$Subject = "online form";
$Name = Trim(stripslashes($_POST['Name']));
$Email = Trim(stripslashes($_POST['Email']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Message = Trim(stripslashes($_POST['Description of project']));
// validation
$validationOK=true;
if (!$validationOK) {
echo "please check your details";
header("Location: http://www.ibdengland.co.uk/thankyou.html");
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Description of project: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"1;URL=thankyou.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"1;URL=thankyou.html\">";
}
?>
You forgot to add the headers.
Example:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: '. $EmailFrom . "\r\n" .
'X-Mailer: PHP/' . phpversion();
Try changing:
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
To:
$success = mail($EmailTo, $Subject, $Body, "From: <".$EmailFrom.">");
you have not use any header.
take help from here. and use it. I think it will help you.
post header like below
$headers = 'From:'.$EmailFrom . "\r\n" .
'Reply-To: '.$EmailFrom . "\r\n" .
'X-Mailer: PHP/' . phpversion();
then replace below
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
with the below code
$success = mail($EmailTo, $Subject, $Body, $headers);
plz try this one. and inform me if this work or not.
Im trying to figure out the problem with the PHP code for submit form, im doing for my friend. It is sending the emails through, but the problem is that the receiver gets a very odd email address. I am attaching an image to have a closer look.
My PHP code is:
<?php
$error = false;
$sent = false;
if(isset($_Post['name'])) {
if(empty($_Post['name']) || empty($_Post['email']) || empty($_Post['comments'])) {
$error = true;
} else {
$to = "linardsberzins#gmail.com";
$name = trim($_Post['name']);
$email = trim($_Post['email']);
$comments = trim($_Post['comments']);
$subject = "Contact Form";
$messages = "Name: $name \r\n Email: $email \r\n Comments: $comments";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From:" . $name . "\r\n";
$mailsent = mail($to, $subject, $messages, $headers);
if($mailsent) {
$sent = true;
}
}
}
?>
Many thanks
It should be like this Sender <HIS#EXAMPLE.COM>:
$headers .= 'From: '.$name.' <'.$email.'>' . "\r\n";
Try adding the headers to the email, like this from PHP mail Manual example 2
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
If you want it to be from an email with a name, this would work
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
Add this to your headers
$headers .= "Reply-To: $replyEmail\r\n";
The From: header should include an email address as well as the name, something like
"From:My Display Name<mydisplayname#gmail.com>\r\n"
<?php
$error = false;
$sent = false;
if(isset($_Post['name'])) {
if(empty($_Post['name']) || empty($_Post['email']) || empty($_Post['comments'])) {
$error = true;
} else {
$to = "linardsberzins#gmail.com";
$name = trim($_Post['name']);
$email = trim($_Post['email']);
$comments = trim($_Post['comments']);
$subject = "Contact Form";
$messages = "Name: $name \r\n Email: $email \r\n Comments: $comments";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: '.$name.' <sender#example.com>' . "\r\n";
$mailsent = mail($to, $subject, $messages, $headers);
if($mailsent) {
$sent = true;
}
}
}
?>
Try this. just change the header.
$headers .= 'From: '.$name.' <sender#example.com>' . "\r\n";
Hi This was not an error.. If you provide SENDER EMAIL then it will display the senders email address instead of this.. Otherwise it will take our hosting address.
I am completely new to PHP scripts and have put together the following code, but I would like the email received to show it is sent from the email field in the HTML form rather than the current "The Tranquility Zone Website [www.tranquilityzone.co.uk#linweb.ahost.me]". Please can you advise what I should change. Many thanks.
<?
$msg .= "Name:\t $_POST[name]\n";
$msg .= "E-mail:\t $_POST[email]\n";
$msg .= "Telephone:\t $_POST[telephone]\n";
$msg .= "Subject:\t $_POST[subject]\n";
$msg .= "Message:\t $_POST[message]\n";
$to = "jenny#tranquilityzone.co.uk";
$subject = "Website feedback message";
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
$mailheaders = "From: The Tranquility Zone Website <www.tranquilityzone.co.uk>\n";
$mailherders .= "Reply to: $_POST[sender_email]\n";
header( "Location: http://www.tranquilityzone.co.uk/thank_you.html" );
#mail ($to, $subject, $msg, $mailheaders);
?>
Change your code to this:
<?php
$msg .= "Name:\t ".$_POST['name']."\n";
$msg .= "E-mail:\t ".$_POST['email']."\n";
$msg .= "Telephone:\t ".$_POST['telephone']."\n";
$msg .= "Subject:\t ".$_POST['subject']."\n";
$msg .= "Message:\t ".$_POST['message']."\n";
$to = "jenny#tranquilityzone.co.uk";
$subject = "Website feedback message";
$headers = 'From: '.$_POST['email']."\r\n".'Reply-To: '.$_POST['email']."\r\n" .
$mailheaders = "From: ".$_POST['email']."\n";
$mailheaders .= "Reply to: ".$_POST['email']."\n";
header( "Location: http://www.tranquilityzone.co.uk/thank_you.html" );
#mail ($to, $subject, $msg, $mailheaders);
?>
$mailheaders = "From: $_POST[sender_email]\n";
$mailheaders .= "Reply-to: $_POST[sender_email]\n";
or
$mailheaders = "From: $_POST[email]\n";
Looks like you have a mispelling in your 2nd mailheaders (mailherders) variable
Try this:
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
$mailheaders = "From: The Tranquility Zone Website <www.tranquilityzone.co.uk>\n";
$mailheaders .= "Reply-to: $_POST[sender_email]\n";
MY DISCLAIMER: I don't condone this type of activity as it looks very shady when you get emails from someone other than the true sender. And yes you could be blacklisted for this.