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.
Related
I need to attach Outlook calendar file (.ics) to the email with mail function.
This is what I have now, but it is not working.
<?php
$firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];
$email = $_POST["email"];
$companyname = $_POST["company"];
$file = "webinar-041016.ics";
$content = file_get_contents($file);
$content = chunk_split(base64_encode($content));
$EmailTo = "mail#mail.com";
$Subject = "New Webinar Registration";
// prepare email body text
$Body .= "Firstname: ";
$Body .= $firstname;
$Body .= "\n";
$Body .= "Lastname: ";
$Body .= $lastname;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Company Name: ";
$Body .= $companyname;
$Body .= "\n";
$headers = 'From: mail#mail.com' . "\r\n" .
'Reply-To: mail#mail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$conf_subject = "Registration Complete ...";
$conf_body = "Dear " . $firstname . ",\n\nThank you..." ;
$conf_body .= "Content-Type: text/calendar; name=\"".$file."\"\r\n" ;
$conf_body .= "Content-Transfer-Encoding: quoted-printable\r\n";
$conf_body .= "Content-Disposition: attachment; filename=\"".$file."\"\r\n\r\n";
$conf_body.= $content."\r\n\r\n";
$conf_headers = 'From: web#mail.com' . "\r\n" .
'Reply-To: web#mail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
// send email
$success = mail($EmailTo, $Subject, $Body, $headers);
$conf_mail = mail($email, $conf_subject, $conf_body, $conf_headers);
// redirect to success page
if ($success){
echo "success";
}else{
echo "invalid";
}
//Attached is an Outlook calendar invite so that you can plan your day accordingly.\n\n
?>
What should I do here? Is my encoding wrong?
You might have already seen this:
PHP Sending Mail
As a suggestion you might wanna have a look into PHPMailer which narrows down the work you have to do, to a single line of code:
$mail->addAttachment('/var/tmp/file.tar.gz');
<?php
$to = 'maryjane#email.com';
$subject = 'Marriage Proposal';
$from = 'peterparker#email.com'; // To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Create email headers
$headers .= 'From: '.$user_email."\r\n". 'Reply-To: '.$user_email."\r\n" . 'X-Mailer: PHP/' . phpversion(); // Compose a simple HTML email message
$message = '<html><body>'; $message .= '<h3 style="color:#f40;">Email:<?php echo $from;?></h3>'; $message .= '<h3>Phone:<?php $phone;></h3>'; $message .= '</body></html>'; // Sending email
if(mail($to, $subject, $message, $headers))
{
echo 'Your mail has been sent successfully.';
} else{
echo 'Unable to send email. Please try again.';
}
?>
$message = '<html><body>';
$message .= '<h3 style="color:#f40;">Email:'.$from.'</h3>';
$message .= '<h3>Phone:'.$phone.'</h3>';
$message .= '</body></html>'; // Sending email
If Its a PHP script, then you can use any PHP function including echo.
Clean way to do this -
echo '<h3>'.$phone.'</h3>';
back again. I wanted to know if there's anyway to specify a particular file for the recipients so that it sends to the emails in the file instead of having to put a comma between all of the emails. Thanks
<?php
$name = $_POST['Chase'];
$email = $_POST['email'];
$message = 'my message';
$from = 'From: email#domain';
$to = 'Email.txt(herE)';
$subject = 'hi world';
$body = "From: $name\r\n E-Mail: $email\r\n Message:\r\n $message";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: email#domain' . "\r\n" .
'Reply-To: ' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if (!mail($to, $subject, $message, $headers)) { echo "Error Sending Email!"; }
else
{ echo "Mail sent!"; }
You could use something like this :-
Note :- Make sure you From email is active when you're hosting this on a server accessible via domain.
$name = "some name";
$email = "test#gmail.com";
$message = 'my message';
$subject = 'hi world';
$headers .= "MIME-Version: 1.0\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: youremail#yourdomain.com' . "\r\n" .
'Reply-To: ' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$handle = fopen("emails.txt", "r");
if ($handle) {
while (($line = fgets($handle)) !== false) {
if (!mail($line, $subject, $message, $headers))
{
echo "Error Sending Email!";
}
else
{
echo "Mail sent!";
}
} //while
fclose($handle);
}//if - outer
else
{
echo "can't open file";
}
emails.txt
test#gmail.com
foo#gmail.com
You can add more emails to the text file, without adding a comma.
P.s :- I'd highly recommend you to use phpmailer.
File security
Make sure that you protect the text file through .htaccess, this is very important.
Here is a Q&A on the subject on Stack:
Allow scripts to read a file but prevent users from viewing the file directly
You can further your research by using "how to protect a text file php" as keywords in your favorite search engine.
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.
Can anyone think of a logical reason to why a contact form which works perfectly well on my 123 reg account, will not work on my clients account? when I test it on my side, I get the email and the form contents through to my inbox perfectly but when the same codes are used on my clients account, with his email address, he receives an email with no data..
<?php
$EmailFrom = "webmaster#pb.co.uk";
$EmailTo = "loans#website.co.uk";
$Subject = "Testing";
$Name = Trim(stripslashes($_POST['Name']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "eMail: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$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=\"0;URL=http://website/thankyou.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
change
"From: $EmailFrom"
to
"From: $EmailFrom" . "\r\n"
Add header.
$Body = 'MIME-Version: 1.0' . "\r\n";
$Body .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$Body .= 'From: '. $EmailFrom . "\r\n" . 'X-Mailer: PHP/' . phpversion();