I brought a shared sever, and got a little storage space. When i run my web site, the mail function works perfectly. Mail has been sent with subject and message to all receivers. But the mail which is sent mentioned "From : ". Headers what i included are not working.
I want to send with my headers Eg:Form: mymail#mysite.com . How can i do it?
<?php
$output="";
if(isset($_POST['submit']) && !empty($_POST['message']))
{
$sub=$_POST['subject'];
$msg=$_POST['message'];
$sql = "select email from login where status='client'";
$query = mysqli_query($con,$sql);
$to=array();
while($row = mysqli_fetch_array($query))
{
$to[] = $row['email'];
$parts = implode(',',$to);
$headers = 'From: mymail#mysiet.com;';
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$subject = $sub;
$content = $msg;
}
if(mail($parts,$subject,$content,$headers))
{
$output="mail sent";
}
else
{
$output="Error in connection, Mail could not be sent. Please try again";
}
}
?>
You need to manually specify the headers, this is the function I use and it delivers to pretty much every provider beautifully. The headers you want are From: and Reply-To: and I also advise the X-Mailer follows what is seen here, I found it years ago via SO as well.
<?php
$to = "user#anotherdomain.com";
$headers = 'From: My Name <email#domain.com.au>' . "\r\n" .
'Reply-To: My Name <email2#domain.com.au>' . "\r\n" .
'X-Mailer: PHP/' . phpversion() . "\r\n" .
'Content-type: text/html; charset=iso-8859-1';
$subject = "My subject line here";
$message = 'Message HTML and Content Here.';
if(mail($to, $subject, $message, $headers)){
// Success Here
}else{
// Failed Here
}
?>
I am not 100% certain it will work for you as I am on a dedicated machine, having said that - I do use it on multiple domains and have never messed with my Apache or php configuration in relation to mail settings.
Read More about the Mail function in PHP: http://php.net/manual/en/function.mail.php
You can try below code, just ripped from php.net
// Additional headers
$headers .= 'To: Mary <mary#example.com>, Kelly <kelly#example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";
Off topic but good to use PHPMailer.
Related
I am not receiving emails from this contact form, but the message seems to sending okay and it also redirects me to the sent page.
I don't have access to the server only via FTP.
PHP
<?php
$to = 'test#gmail.com';
$subject = $_POST['subject'];
$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];
$body = <<<EMAIL
<html>
<p><h3>Email Submited From Website.</h3></p>
<p><strong>Name:</strong> $name</p>
<p><strong>Email:</strong> $email</p>
<p><strong>Subject:</strong> $subject</p>
<p><strong>Message:</strong> $comment</p>
</html>
EMAIL;
// 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";
// Additional headers
$headers .= 'To: test email' . "\r\n";
$headers .= 'From: <website#mt.co.uk>' . "\r\n";
//$headers .= 'Cc: noreply#example.com' . "\r\n";
//$headers .= 'Bcc: noreply#example.com' . "\r\n";
if ($_POST['submit']){
mail($to, $subject, $body, $headers);
header ("Location: message-sent.php");
die();
} else {
header ("Location: message-failed.php");
die();
}
?>
Check if mail is actually being sent:
if (mail($to, $subject, $body, $headers)===false) {
echo "Not sent!";
} else {
echo "Sent!";
}
Change this:
$headers .= 'To: test email' . "\r\n";
$headers .= 'From: <website#mt.co.uk>' . "\r\n";
To this:
$headers .= "To: $to <test email>\r\n";
$headers .= "From: website#mt.co.uk <website#mt.co.uk>\r\n";
Also, you need to sanitize the subject and body of the email so that the email arrives, but this will usually be reflected in the results after email() reports a success, in that case the email will bounce, go to the spambox, or simply be refused.
If your hosting provider doesn't have an email server, you could try to use a free email server and phpMailer. https://github.com/PHPMailer/PHPMailer
my php mail() function is not working even its right here it is
$to = $email_id;
$sub = "FORGOT PASSWORD";
$msg = $password;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'From: Your name <example#gmail.com>' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$mail= mail($to,$sub,$msg,$headers);
if($mail)
{
?>
<script>alert('Your password has been successfully sent to you');</script>
<?
}
else
{
?>
<script>alert('Please try again later');</script>
<?
}
its alert if part i.e. Your password has been successfully sent to you but i did not received any email please help me and i am not using any HTML css in sending this mail.
your headers are incorrect use your headers in this way it will resolved your problem getting true part is not a big deal
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'From: Your name <example#you_domain_name.com>' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
if not resolved give me the result you get using var_dump($mail); showing bool(true)
use
$mail= mail($to, $sub, $msg, $headers);
You dont need string as all variables are Already string.
Use this mail($to, $sub, $msg, $headers),
If it returns true, then check your spam folder.
Write your domain name
$headers .= 'From: Your name <example#yorudomainname>' . "\r\n";
example <example#stackoverflow.com/>
no need to use "" in the mail function if you are storing it in a variable allready.
second thing check what you are getting in $email_id; variable is it the correct email address you are trying to send email .
simply use like this
<?php
$to = $email_id;
$sub = "FORGOT PASSWORD";
$msg = $password;
$headers = "From: webmaster#example.com" . "\r\n" .
"CC: somebodyelse#example.com";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$mail=mail($to,$sub,$msg ,$headers);
if($mail)
{
?>
<script>alert('Your password has been successfully sent to you');</script>
<?
}
else
{
?>
<script>alert('Please try again later');</script>
<?
}
?>
Update
also please check your spam folder. as if you are using other domain as from email these emails may go to the spam folder . or you can use these headers
$headers = "From: webmaster#example.com" . "\r\n" .
"CC: somebodyelse#yourdimain.com"; // enter your domain email
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
For my project I had to create a function that sends two email. One to the customer and the other to the a seller. Both emails will have different contents.
I wrote the two function using the standard PHP mail function as below.
$to = "xxxx#xxxx.com";
$subject = 'xxxx';
$message = "hello"
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to, $subject, $message, $headers);
Now, While testing the system on my own company's web server both emails seems to be sent and received. However, when I migrated the same system into an external server. only one email gets sent. primarily, the first email in the stack.
While I suspect the issue has something to do with the later server configuration, I am wondering where should I go next to debug this issue.
There were a few things in your "posted" code that were missing.
A missing semi-colon at the end of $message = "hello" (unless that was a typo/paste error?) and a dot in the first $headers
Also, not having a From: header attribute will surely result having the Email sent to and regarded as SPAM.
Having fixed those issues and added extra header information, the following code worked and did not end up in my SPAM, but the INBOX successfully.
<?php
$to = "xxxx#xxxx.com";
$email = "email#example.com";
$subject = 'xxxx';
$message = "hello";
$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();
mail($to, $subject, $message, $headers);
?>
Or with a success echo'ed message:
<?php
$to = "xxxx#xxxx.com";
$email = "email#example.com";
$subject = 'xxxx';
$message = "hello";
$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(mail($to, $subject, $message, $headers))
{
echo "Message sent.";
}
else{
echo "Something went wrong.";
}
?>
Visit the PHP.net website for more information on the mail() and header() functions.
http://php.net/manual/en/function.mail.php
<?php
// multiple recipients
$to = 'ali.dzinemedia#gmail.com';
// subject
$subject = 'Birthday Reminders for August';
// message
$message = '<html>
<head></head>
<body>Content here and this is a link</body>
</html>';
// To send HTML mail, the Content-type header must be set
// Additional headers
$headers = 'To: Mary <ali.dzinemedia#gmail.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <ali.dzinemedia#gmail.com>' . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset: utf8\r\n";
echo "To : ".$to;
// Mail it
mail($to, $subject, $message, $headers);
?>
please solved this . when i added Download in the mail body mail not send.
if i remove this a tag mail sent and all other content display as per my requirement .
I dont know where is the exact problem, i m using godady hosting with PHP 5.3 version.
if any one have better solutions please share with me .
I've adjusted your code a little bit. Main change is in From: header - $header = "From: \"HCS Support Team\" <$from_id>\r\n" . "Reply-To: $from_id\r\n";
$erm.= '<TR>
<TD WIDTH="50%">' . "Download-" . $j . '</TD>
<TD WIDTH="50%">Download</TD>
</TR>';
$from_id = "support#xyz.com";
$header = "From: \"HCS Support Team\" <$from_id>\r\n" . "Reply-To: $from_id\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$header .= 'MIME-Version: 1.0' . "\r\n";
$header .= 'X-Mailer: PHP/' . phpversion() . "\r\n";
$subject = "Request for Case Study Solution Received";
#mail("ali.dzinemedia#gmail.com", $subject, $erm, $header);
It seems the mail is being sent, but it goes straight to SPAM folder. Please read about spam rules which make the mails go to spam folder: http://spamassassin.apache.org/tests_3_3_x.html
In your case the main problem with gmail is probably it's being sent with standard PHP mail function. Please try PHPMailer or PEAR::Mail.
The rules which are met by spamassasin in your mail are:
HTML_MESSAGE
HTML_MIME_NO_HTML_TAG
MIME_HTML_ONLY
I'm pretty new to PHP so don't mind the #... was a quick fix for opening the script without errors
I'm currently working on a mail script and its working pretty well.
Sadly it sends the text the user enters as a .txt file instead of plain text
Basically the form is stored in messenger_mailsend.php and the content of the Textarea gets to messenger_mailsend_controller.php by using $_POST[].
#$inhalt = $_POST['inhalt'];
$message = strip_tags($inhalt);
if(isset($_POST['submit'])){
#mail($mailto, $subject, 'why not zoidberg?', $headers);
echo 'The mail was sent!';
}
'why not zoidberg' is the test text i used to check if theres sth wrong with the var, actually it says mail($mailto, $subject, $message, $headers);
is the code I use to get the typed message from the form, remove the tags and store it as $message.
If I do a var_dump it says 'I am content' (what was typed in the form)..
when the $message var is replaced by some plain text it still gets sent as TEXT.txt
The code i use for the $headers is:
$headers .= 'From:' . $usrmail . "\n";
$headers .= 'Reply-To:' . $reply . "\n";
$headers .= 'X-Mailer: PHP/' . phpversion() . "\n";
$headers .= 'X-Sender-IP:' . $_SERVER['REMOTE_ADDR'] . "\n";
$headers .= 'Content-type: text/html; charset=ISO-8859-1\r\n';
$headers .= 'Cc: ' . $cc . "\n";
$headers .= 'Bcc: ' . $bcc . "\n";
-- Solution: By setting the content-type to text/plain it works, thanks anyone! --
Well how can you expect the mail to be sent as html when you are stripping all the html tags before sending....
However, if you want to send the html mail, you have to define the same in the headers before sending. See the snippet:
$to = 'bob#example.com';
$subject = 'Website Change Reqest';
$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
$headers .= "CC: susan#example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
#$inhalt = $_POST['inhalt'];
$message = strip_tags($inhalt);
And then you send the mail like this:
mail($to, $subject, $message, $headers);