I have a PHP contact form on my website. I have been using it for about a year now without any problems. Nothing has been updated on my website that has do to with the contact form. However, all of a sudden, when a user enters "line breaks" or "paragraphs" in the message box, when I receive the message, instead of having several paragraphs I have 1 long paragraph with "\r\n" in place of line breaks.
Here is the code:
$to = "info#mycompany123.com";
$headers = "From: $email";
$subject = $subject;
$body = "Name: $name\n\n"
. "Email: $email\n\n"
. "Subject: $subject\n\n"
. "Message: $message" ;
mail ($to, $subject, $body, $headers) ;
I really do not know why it started doing this out of the blue but any help is greatly appreciated!
try to convert your message using the nl2br($row['message']); function when you are displaying the messages.
$row['message'] is just an example, it can be any string.
Related
Hallo I've got a problem with sending html E-mails with a dyanamic Link via PHP.
That is my PHP Code:
$empfaenger = $_POST['email'];
$test = sha1($_POST['email']);
$betreff = "Test Mail";
$from = "From: Peter <tets#gmail.com>\n";
$from .= "Reply-To: test16#gmail.com\n";
$from .= "Content-Type: text/html\n";
$text = "Please click <p><a href='http://defaultpage/default.php?res=".$test."'>here</a></p>.";
mail($empfaenger, $betreff, $text, $from);
In the mail Log all looks normal like the mail is sended, but I didn't receive one. In PHP error Log also nothing. If I set $test to a specified string it's working as expected, but not with the dyanamic variable $test. I hope that someone can help me becuse I can't get rid of this problem.
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
I am having trouble with sending emails through PHP.
So I have a form which submits to a PHP script which sends an email:
<?php
$to = "myemail#email.com";
$subject = "[Contact Form]";
$name = $_POST["name"];
$contactNumber = $_POST["contactNumber"];
$email = $_POST["email"] ;
$message = $_POST["message"];
$body = "Someone has sent a new message from the contact form. \n \n Message from: " . $name . "\n Contact Number: ". $contactNumber ."\n Email: ". $email ."\n \n Message: ". $message;
if (mail($to, $subject, $body)) {
echo ("<p>Email successfully sent!</p>");
} else {
echo ("<p>Email delivery failed…</p>");
}
?>
And the email is sent fine when for example the message is one line such as:
"Hi there how is it going?"
And fine if it is multiple lines such as
"Hi there
how is it going?"
But when I try and type a message with a comma such as
Hello there,
how is it going?
It fails?
Is there a way I can just treat the whole thing as a string possibly? Would this also fail on any other characters or is this issue just because of the way I am writing the PHP script?
This might be an obvious fix but I am new to PHP so apologies! I have tried looking around for an answer but nothing seems to fix what I am looking for.
Thanks for any help!
Try using headers in your mail function, like this:
$headers = 'MIME-Version: 1.0\r\n';
$headers .= 'Content-type: text/html; charset=UTF-8\r\n';
mail($to, $subject, $body, $headers)
Heres my little code
$to = 'target#adress.pl';
$adres='author#adress.pl';
define('ADR','author#adress.pl');
$subject='Invoice delivery confirmation for '.$adres;
$message=$adres.' confirmed invoice delivery';
$headers = "From: ".$adres."\r\n" .
"Reply-To: ".$adres."\r\nContent-Type: text/plain; charset=utf-8" ;
if (mail($to, $subject, $message, $headers)) echo ' Confirmation has been sent to '.$to.'<br />';`
When i use variables with or without concatenation then headers in sending message are empty - they are replaced with default admin adress. Offcourse variable $adress itself is not empty as it works properly in $subject and $message variables. But if i replace variables with ADR constant or plain text then they do work. Is it PHP, server settings or something else?
Im new to this PHP stuff so please excuse my ignorance
Im after having just one input text box in my flash website where a person just enters there email address and at the click of a button it sends an email to me to a pre defined email address with a predefined subject heading and the email address that was entered in the body of the email
Anyone know of any links or can give some help
all the ones i have found want names email subject message and so on
Any help is appreciated
Mark
EDIT
ok I have the following
In flash I have an input text converted to a movieclip called "addy". Inside the movie clip which has the inputbox which has the variable name "emailaddy"
A Button called "email"
The code i Have running when "email" is clicked is
on (release) {
form.loadVariables("email.php", "POST");
}
the email.php script is as follows
<?php
$sendTo = "mark#here.co.uk";
$subject = "Subscribe to Website";
$headers = "From: Website";
$headers .= "<" . $_POST["addy"] . ">\r\n";
$headers .= "Reply-To: " . $_POST["addy"] . "\r\n";
$headers .= "Return-Path: " . $_POST["addy"];
$message = "Please Subscribe me to Website";
mail(recipient, subject, message, other headers);
mail($sendTo, $subject, $message, $headers);
?>
when I click the button nothing happens
what im after is when the button is clicked for and email to be sent in the following format
To: "mark#here.co.uk"
From: email address specified in text field "addy"
Subject: "Subscribe to Website";
body: "Please subscribe me to Website"
Your help is greatly appreciated
mark
The following code might help:
<?php
$user_mail=$_POST["mail"]; //or $user_mail=$_GET["mail"]; Set to your convenience!
$to_mail="abcde#xyz.com"; //Change to your email address
$message="New user's Email: ".$user_mail; //Change to your requirements
$subject="New user registered"; //Change to your preferred subject
$from="registration#yourwebsite.com"; //Change to your website mail id
mail($to_mail,$subject,$message,"From: $from\n");
To know more about the mail function, please see the documentation.
Well in depth you can do like this
<?php
if($_POST){
$userEmail = $_POST0["emailaddy"]; // textbox variable name comes here
$to = 'abc#xyz.com'; //write down here your email
$subject = 'Subscribe to website'; // your subject goes here
$message = 'Please Subscribe me to Website'; // Mail body message
$headers = 'From: ' . $userEmail . "\r\n" .
'Reply-To: ' . $userEmail . "\r\n" .
'Return-Path: ' . $userEmail; //can send x-Mailer also
mail($to, $subject, $message, $headers);
}else{
echo "Invalid Request";
return false;
}
Don't forget to check first $_POST is happened or not. No need to send Return-path instead of this use x-Mailer which sound good for other mail service providers.
To know more about this read documentation here.
If you want to connect to an SMTP server ,like Postfix or gmail there is a neat php library called PhpMailer.
It is well documentated, so you should be good to go by googleing it :)
Is my $headers and or second mail() function incorrect or improper? My page has a form that when you fill out will send an email to the recipient, then a second one to via a text message (many carriers has a text to email feature). When I submitted the form the first mail() function works, but the second one doesn't. Any ideas? Also, I'm doing this because I want it to send an email and a text message (I thought this was a great idea) so that the recipient is notified that there's an email that needs his/her attention.
Here's what I mean.
// HTML FORM here, collects just name, email, subject line, message
// When the form is submitted it does this...
$to = "recepient#email.com";
$to_sms = "recepienttextnumber#tmomail.net";
$subject = filter_var($_POST['subject'], FILTER_SANITIZE_STRING)." - FORM";
$headers = 'MIME-Version: 1.0' . "\r\n" .
'Content-type:text/html;charset=iso-8859-1' . "\r\n" .
'From: noreply#email.com' . "\r\n" .
'Reply-To: info#email.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$body = "
<html>
<p>This is an automatic email notification. <strong>Please do not reply to this email</strong></p>
<p>You received a message from ". $name . " that needs your attention ASAP.!</p>
<p>Client name: ".$name."<br />
Client phone: ".$phone."<br />
Email: ".$email."<br />
About: ".$_POST['subject']."<br />
Message: ".$message."</p>
</html>";
$body_sms = "Great news! ".$name." has contacted you via the FORM. Check your email now.";
// Send Email & Text Notification
//Here sends out the form via email
mail($to, $subject, $body, $headers);
//alternatively a second message is sent to another
mail($to_sms, $subject, $body_sms, "From: FORM");
//Echos a thank you.
I suggest you make a copy of your $headers and name it $headers2 and use
mail($to, $subject, $body_sms, $headers2);
that may be the problem.