A user fills out a form which is sent to my email via the variables their data is read into.
I want to have headers above each users entry, and have these appear bold in the email.
The email should read:
OCCUPATION:
Data the user entered.
I have tried
$Occupationheader = "<strong>"."OCCUPATION"."</strong>"."\n\n" ;
and
$Occupationheader = "<strong>OCCUPATION:<strong>\n\n";
The data is sent to the email, as follows: (this works, but want to format the headings in bold).
mail( "myemailaddress", "subjectmatter",
$Occupationheader.$Occupation);
Any ideas?
Thanks guys.
$mailContent = "<html>
<body>
<strong>HEADER</strong>
<br/>message
</body>
</html>";
NOTE: This is provided as an additional answer.
Without seeing full source code, am providing my (additional) answer below.
The following, need to be present in your code, in order to send out Emails in HTML format:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
As per the PHP manual on the subject: http://php.net/manual/en/function.mail.php
Related
I have a questionnaire form on the web. After filling in this form, I send it to me by email, using the PHP function mail(). The form body and the data it contains, including the private message are displayed correctly on gmail.com. The problem, however, occurs in the header of the email itself. Some characters are displayed incorrectly.
Here is a sample header:
$headers = "Content-Type:text/html; charset=utf-8\r\n";
$headers .= "From:" .$email . "\r\n";
$headers .= "Reply:" . $email . "\r\n";
$headers .= "X-Mailer: PHP/". phpversion() . "\r\n" ;
Required display of email subject:
Nový dotaz -- námět, od Fořt Petr <p.fort1990#gmail.com>
Simultaneous displaying of the subject:
Nový dotaz -- námÄ☒t od: FoÅ☒t Petr <p.fort1990#gmail.com>
The squared times symbol is more like a rectangle.
Is anything wrong? Or where should I look for a mistake?
I'm not sure \r\n works on all platforms
see : Which line break in php mail header, \r\n or \n?
instead
("xxx\r\n\yyy");
use
Header('xxx');
Header('yyy');
or use PHP_EOL, not "\r\n"
Problem solved. My hosting provider uses different character encoding for the headers - I can't explain why, but the following php function will do it all.
function recode_to_utf8 ($text, $encoding = "utf-8")
{
return "=?$encoding?Q?" . imap_8bit($text) . "?=";
}
And now all you have to do is send an email using the mail () method in combination with the method defined above recode_to_utf8(). Like this:
mail(recode_to_utf8($mail_to), recode_to_utf8($subject), recode_to_utf8($message), recode_to_utf8($headers));
I hope it helps others if they have the same problem as me.
I'm trying to figure out with email confirmation function via email, received by user.
If I have <input type='submit' value='Accept' id='btn1'>, (which is correct way shown by ADyson, instead double quotes: <input type="submit" value="Accept" id="btn1">), then how do I use PHP $_POST['acceptval'] for confirmation from this HTML, which must record value to MySQL database from received message form by included ID, then to pass this condition from the website.
So, if I will include require 'connect.php'; to code below, and will get data for to, message, subject, I will receive message to my userreceiveremail#gmail.com, then I want allow user press button, and record value to his record field, but I can't figure out, how it works:
<?php
$to = "userreceiveremail#gmail.com";
$subject = "Confirmation notification";
$message = "
<html>
<head>
<title>Accept registration</title>
</head>
<body>
<p>Hello, dear User! Please, accept your registration</p>
<input type='submit' value='Accept' id='btn1'>
</body>
</html>
";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <senderemail#gmail.com>' . "\r\n";
$headers .= 'Cc: Some text' . "\r\n";
mail($to,$subject,$message,$headers);
echo "Mail sent successfully";
?>
Maybe my scenario does not correspond to the classic or correct approach to solving this particular task, because I'm just trying to figure out, how to get desired result, anyway yet I can't find any close example for this.
Any advice, guide or example would be very helpful
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
I have a code to send html mail with php on cpanel but doesn't send without any errors. I have tested plain text mail and that is working fine, but once I add the header like below, it doesn't work.
//send html mail
ini_set('sendmail_from', 'info#toludimaokojie.com');
$headers = "From: info#toludimaokojie.com\r\n"."X-Mailer: php";
$headers .= "Content-type: text/html\r\n";
$html = '<html>
<body>
<h2>Result Analysis for Test With Reference Number:'.$reference.'</h2>
<br/>
<p><b>Personality: '.$personality_mail.'</b></p>
<br/>
<p><b>MBQ Score: '.$resultTotal.'</b></p>
<br/>
<ul>'.$analyseData.'</ul>
<pre>Mail Sent on '.date("l, F Y H:i:sa").'</pre>
</body>
</html>';
mail("olaegbesamuel#gmail.com", "MBQ TEST ANALYSIS", $html, $headers);
This doesn't work. Please help, i guess am doing everything correctly here. I have tested without html and confirmed that mail is working
You have defined $headers with all mandatory email parameters but look at your $header variable, there are two things need to be changed,
1) You have used $header and $headers both so use either of them and append them to one variable.
2) your 2nd line of $header variable is missing . to append the previous header values, so the corrected code should be:
$headers = "From: info#toludimaokojie.com\r\n"."X-Mailer: php";
$headers .= "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
As you missed . operator in 2nd line, it will remove From header and so it would not be sending email.
Try after changing these lines.
The following PHP code works perfectly, but it is not doing line breaks for some reason.
PHP:
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=utf-8\n";
$headers .= "From: '".$title."' <".$store_email."> \n";
$subject = "New Payment Received";
//MESSAGE
$message = "New payment was successfully recieved through paypal payment terminal:";
$message .= "\r\n\nFrom ".$paypal->pp_data['payer_email'];
$message .= "\r\nPaid: ".$paypal->pp_data['payment_gross']." ".$paypal->pp_data['mc_currency'];
$message .= "\r\nDate: ".date('d/m/Y');
$message .= "\r\nTime: ".date('g:i A');
mail($admin_email,$subject,$message,$headers);
Any wonder what's wrong? Thanks in advance.
You're sending HTML e-mail. Line breaks have no meaning in HTML, you'll need <br /> tags.
The direct answer ceejayoz gives is correct and to the point in that the html element <br> is needed because it is a html email.
The bigger issue is that not all email is readable in html (example: user doesn't allow html emails). Anyone sending email should send it in 2 parts. One being a html formatted message and the other "alternative" in plain text. In that way the recipient will be able to read the email regardless of email reader.
The \r\n line break works in plain text alternative part and in html<br> or other elements as needed to format.
Doing this will avoid the next question. Recipients are complaining my emails are blank.
I got my PHP mail form working great and just have one last touch I wanted to add. Basically I am pulling the info from the form like this:
$fields{"Comments"} = "Additional Comments by Fitter: ";
The HTML for this field is:
<textarea name="Comments" id="styled" onfocus="this.value=''" onblur="setbg('white')">Enter your comment here...</textarea>
The email would then displays:
Additional Comments by Fitter: Enter your comment here...
I would like the info being pulled to be a different color. I have tried:
$fields{"<span style='color:red;'>Comments</span>"} = "Additional Comments by Fitter: ";
but then no comments are displayed (I assume I am not wrapping it right). I have:
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
At the top of the file as well. Any help would be great. Thanks.
You need to wrap the value, not the key.