Contact form error PHP - php

Trying to write a contact form script only my following page isnt processing...
<?php
$rpname = $_POST['name'];
$rpnumber = $_POST['phone'];
echo $rpname;
echo $rpnumber;
$rpname = $_POST['name'];
$rpnumber = $_POST['phone'];
$to = "liam#.co.uk"; // CHANGE THIS TO EMAIL YOU WANT
$subject = "Phonecall Request"
//begin of HTML message
$message = "
Phone call request -
From : $rpname,
Number: $rpnumber
";
$headers = "MIME-Version: 1.0rn";
$headers .= "Content-type: text/html; charset=iso-8859-1rn";
$headers .= "From: Website Enquiry";
if (isset($rpname))
{
// now lets send the email.
mail($to, $subject, $message, $headers);
$page='index.html';
header('Location:'.$page);
header('Location: ' . $_SERVER['HTTP_REFERER'] . '?e=Message Sent!');
} ?>
Ive tried to echo the variables at the top but im getting a blank page with no source...

You need a semicolon (;) after $subject = "Phonecall Request".
You would have caught this error yourself if your configuration had error reporting enabled. Do this is in your php.ini file. This will most likely be located in /etc/php5/cgi/. Add the following lines:
display_errors = On
error_reporting = E_ALL
If you don't have access to this on your server, you can add it on a per-document basis, by including the following line at the beginning of each PHP document:
ini_set('display_errors', '1');
error_reporting(E_ALL);

I think you have a copy error on that lines:
$headers = "MIME-Version: 1.0rn";
$headers .= "Content-type: text/html; charset=iso-8859-1rn";
$headers .= "From: Website Enquiry";
it should be this:
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: Website Enquiry";
The rn makes no sense exept you want \r\n which is a linebreak.

Related

How to send a html / html5 template email with php?

I want to send a html / html5 email with PHP. I have a html template with the email message which I am planning to send to a user.
HTML template - default-message.php
<?php include 'mailservice.php'; ?>
<div>
<h3>Dear <?php echo $name; ?>,</h3>
<p>I send you this custom message!!</p>
</div>
PHP - mailservice.php
/* getting the content from te default-message.html file*/
ob_start();
include('default-message.php');
$message = ob_get_contents();
ob_end_clean();
$name = "John";
$to = "sadas#yahoo.com";
$subject = "Hello";
$headers .= 'From: Me <abc#mysite.com>' . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail ($to, $subject, $message, $headers);
You need to set the variables before you include the template script, so they'll be expanded when the template runs.
ob_start();
$name = "John";
$to = "sadas#yahoo.com";
include('default-message.html');
$message = ob_get_contents();
ob_end_clean();
$subject = "Hello";
$headers .= 'From: Me <abc#mysite.com>' . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail ($to, $subject, $message, $headers);
Also, default-message.html should not contain <?php include 'mailservice.php'; ?>, because then it will go back and forth with each script including the other.

HTML not being rendered in email

$message = 'What are the other benefits to saying "nah" that you can think of? - ' . $_POST['other-benefits'] . '<br>' .
'What are you pledging to do? - ' . $_POST['what-pledge'] . '</p>';
I am trying to do a break after each line in php but with embedded HTML. When I send an email(function not included) it doesn't render with breaks. It literally just types out the as a string. Is there a way to correct this?
Given the lack of information given about the problem, I can only assume that the issue is that the headers of the email have not been set to send HTML emails.
You'll have to do something along the lines of:
// Setup email content.
$to = "example#email.com";
$subject = "Example HTML email";
$message = 'What are the other benefits to saying "nah" that you can think of? - ' . $_POST['other-benefits'] . '<br>' .
'What are you pledging to do? - ' . $_POST['what-pledge'] . '</p>';
// Setup headers.
$headers = "From: from#email.com\r\n";
$headers .= "Reply-To: replyto#email.com\r\n";
$headers .= "CC: susan#example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
// This next one is where the magic happens.
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
// Send!
mail($to, $subject, $message, $headers);
Refer to: https://css-tricks.com/sending-nice-html-email-with-php/
In order to send an email containing html, pay special attention to the following headers:
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
Example Code:
$otherbenefits = $_POST['other-benefits'];
$whatpledge = $_POST['what-pledge'];
$email = <<< LOL
<html>
<body>
<p> What are the other benefits to saying "nah" that you can think of? - $otherbenefits <br> What are you pledging to do? - $whatpledge </p>
</body>
</html>
LOL;
$emailaddress = "personsemail#website.com";
$subject = "Test Email";
$headers = "From: noreply#server.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($emailaddress, $subject, $email, $headers);
For more information, please visit PHP.net regarding the mail() function and how to send email as HTML.
http://php.net/manual/en/function.mail.php

add image to PHP email script

I've done some research on this issue but still can't find an answer that I understand. Basically I'm trying to add a Logo to the emails sent via my email PHP script. The code of my PHP script is:
<?php
$name = $_POST['Name'];
$email = $_POST['Email'];
$sub = $_POST['Subject'];
$message = $_POST['Message'];
$Subject = "$sub";
$Sendto = "Omitted for privacy reasons";
mail($Sendto,$Subject,
"$message
Email: $email
Name: $name
"
,"From: $email,$name");
?>
How do I go about putting an image held on my server in Images/logo above the email:$email part of the message?
thanks
As a side question can anyone provide me with a guide or reading on how to beautify the message as its so plain
What you might do is to send the mail not as "text/plain", but as "text/html".
You e-mail content is then basically a static webpage and you can insert images to.
Example Code for Mail with HTML Content
$to = 'to#someone.com';
$subject = 'The Subject';
$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
$headers .= "CC: other#someone.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
// this is the important header to set the type
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
// now $message can be a static html page like:
$message = '<html><body>';
$message .= '<h1>Hello, World!</h1>';
$message .= '</body></html>';
// with image embedded
$message = '<html><body>';
$message .= '<h1>Hello, World!</h1>';
$message .= '<img src="http://i.stack.imgur.com/Qmw3Z.jpg?s=32&g=1" alt="AVTR" />';
$message .= '</body></html>';
Important: If you insert something into the message coming from POST, do not forget to escape it properly with htmlentities($_POST['somevar']) or striptags.
Then send mail:
mail($to, $subject, $message, $headers);
Answer to side-quest: "can anyone provide me with a guide or reading on how to beautify the message as its so plain". When you send the mail as HTML you might apply CSS styles to your HTML.
Starter tutorial: http://webdesign.tutsplus.com/articles/build-an-html-email-template-from-scratch--webdesign-12770
you might also google for "html email templates", download one and modify to your needs

PHP mail() Not displaying HTML

We've recently upgraded to a Plesk Parallel Linux Server and it appears as if the PHP settings are ignoring headers! The emails are receiving fine, but display the HTML tags.
The phpInfo() file can be viewed here: https://www.pressgofer.com/phpInfo.php
The PHP itself should be okay, but have included it here anyway.
PHP Mail Code
$email = "example#example.com";
$message = "<h1 style='font-family:Helvetica,Arial;font-size:17px'>Your account has a password reset request</h1>";
$headers = "From: noreply#pressgofer.com \r\n";
$headers .= "Reply-To: noreply#pressgofer.com \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($email, "Reset password notification", $message, $headers);
Many thanks,
Nick
your phpinfo shows that mail.add_x_header is OFF. you need to turn it on
To enable the X-Mail header, set mail.add_x_header to 1 in your php.ini
<?php
$to = "yourplace#somewhere.com";
$subject = "My HTML email test.";
$headers = "From: sinha.ksaurabh#gmail.com\r\n";
$headers .= "Reply-To: sinha.ksaurabh#gmail.com\r\n";
$headers .= "Return-Path: sinha.ksaurabh#gmail.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "<html><body>";
$message .= "<h1> This is a test </h1>";
$message .= "</body></html>";
if ( mail($to,$subject,$message,$headers) ) {
echo "The email has been sent!";
} else {
echo "The email has failed!";
}
?>
sending mail from php: headers are interpreted as body?
Issue was associated with MIME type and server interpretation- no \r needed.

Send HTML mails using PHP [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Sending HTML email from PHP
I am sending emails using php through my gmail account. And I am using ssmtp other than sendmail. I am using following php code to send the mail.
$to = "mymail#gmail.com";
$from = "mymail#gmail.com";
$subject = "Testing mail";
$header = "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html; charset: utf8\r\n";
$headers = "From:" . $from;
$message = "<html><body><head></head>";
$message .= "<h1>Hello, World!</h1>";
$message .= "</body></html>";
if(mail($to,$subject,$message,$headers)){
echo "Mail Sent.";
} else {
echo 'failed';
}
But I am getting a mail like below
<html><body><head></head><h1>Hello, World!</h1></body></html>
What may be the reason for it? I am using ssmtp MTA in Ubuntu.
Try using the following in your code
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
This link will be most helpful
Sending HTML email with PHP
You are using header (singular) and headers (plural) indistinctly. The correct way is using plural for the headers:
$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
This is a good reading:
http://css-tricks.com/sending-nice-html-email-with-php/
use this
<?php
$to = "mymail#gmail.com";
$from = "mymail#gmail.com";
$subject = "Testing mail";
$header = "MIME-Version: 1.0\r\n";
$header .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$header .= "From:" . $from;
$message = "<html><body><head></head>";
$message .= "<h1>Hello, World!</h1>";
$message .= "</body></html>";
if(mail($to,$subject,$message,$headers)){
echo "Mail Sent.";
} else {
echo 'failed';
}
?>
Thats because PHP does not make new lines by it self. You can use echo "Lalala \n" to make new lines.

Categories