i have a php script
<?php
$to = 'somebody#somedomain.com';
$subject = 'Test mail';
$message = 'mysitedomain.com';
$from = 'support#mysitedomain.com';
$headers = 'From:' . $from;
mail($to,$subject,$message,$headers);
echo 'Mail Sent.';
?>
When i run this code mail not send. If i change message to mysitedomaincom (without dot before com) the mail send succesfull.
Anybody have a solution for this?
This codes that tells the mailer and the recipient that the email contains well formed HTML that it will need to interpret
If you want you can change content of $message, now with this codes you can send HTML content mail.
<?PHP
$to = 'somebody#somedomain.com';
$subject = 'Test mail';
$headers = "From: Support <support#mysitedomain.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>mysitedomain.com</h1>';
$message .= '</body></html>';
mail($to, $subject, $message, $headers);
?>
Related
I am using this basic php code to send out a html email.
When i use email#email.com as a to address the script works.
However, when i try to use email.2015#gmail.com the script says:
Parse error: syntax error, unexpected '#' in /home/u925912002/public_html/send_email.php on line 3
My code:
<?php
$to = ‘email.2015#gmail.com’;
$subject = 'I need to show html';
$from ='example#example.com';
$body = '<p style=color:red;>This text should be red</p>';
ini_set("sendmail_from", $from);
$headers = "From: " . $from . "\r\nReply-To: " . $from . "";
$headers .= "Content-type: text/html\r\n";
if (mail($to, $subject, $body, $headers)) {
echo("<p>Sent</p>");
} else {
echo("<p>Error...</p>");
}
?>
please can someone show me what i'm doing wrong. thanks
For your question recently closed: https://stackoverflow.com/questions/34106770/send-email-using-php-from-address-not-working
Try this:
$headers .= "From: Your Name <$from>\r\n";
and you can also add the 5th mail parameter:
mail($to, $subject, $body, $headers, '-finfo#userforum.com').
Works for me with these headers:
$from = "$name <$email>\r\n";
$to = "$username <$useremail>\r\n";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= "From: $name <$email>\r\n";
$headers .= "Reply-To: $name <$email>\r\n";
you are using Apostrophe(‘) instead of quotes(')
try this -
$to = 'email.2015#gmail.com';
instead of this -
$to = ‘email.2015#gmail.com’;
I would like to send an email to my gmail account using some simple PHP code. The code below works in terms of execution, however the problem is even thought is says "Message Sent" I am not receiving my email in my gmail account. Please advice
ini_set('SMTP',"smtp.gmail.com");
$to ="example#gmail.com"; // this will be replaced with my actual email
$from ="example#gmail.com"; // this will be replaced with senders email
$message = $_GET['Message'];
$subject = "This is a test";
if(mail($to,$subject,$message,$from))
{
echo "Message Sent";
}
else
{
echo "Message Not Sent";
}
Steps to send a simple email
Go to google
Search for "PHP Mail"
Click the first result
Read, read, keep reading, wait, read it over, read on
Enjoy!
But seriously:
(Examples are taken from PHP.net)
Example 1
Sending a simple email
Using mail() to send a simple email:
<?php
// The message
$message = "Line 1\r\nLine 2\r\nLine 3";
// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70, "\r\n");
// Send
mail('caffeinated#example.com', 'My Subject', $message);
?>
Example 2
Sending mail with extra headers.
The addition of basic headers, telling the MUA the From and Reply-To addresses:
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
Use his line of code:
$to ="example#gmail.com"; // this will be replaced with my actual email
$from ="example#gmail.com"; // this will be replaced with senders email
$headers = "From: ".$from."\r\n";
$headers .= "Reply-To: ".$from."\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";
$message = $_GET['Message'];
$subject = "This is a test";
mail($to, $subject, $message, $headers);
How can i add tag inside the email php ? for instance , i want to bold my $for_pass .Any idea ? thanks
$subject = "Password Recovery";
$message = "Hi! Your member password is <strong>$for_pass</strong>";
$from = "smilepartyplanner2014#gmail.com";
$headers = "From:" . $from;
// send mail
$mail_sent = #mail( $forgot_email, $subject, $message,$headers );
//echo "Thank you for sending us feedback";
?>
<script>
alert("Your password has been sent to your email address. ");
</script>
<?php
You need send MIME headers in your mail to tell its HTML, as follows:
$headers = "From:" . $from . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$mail_sent = #mail($forgot_email, $subject, $message, $headers);
As you have it in the mail body but you need to declare content type on header
...
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= "From:" . $from;
the message body can have any inline styling you wish.
I'm running a website loccaly useing WAMP and have installed Test Mail Server Tool to act as a mail server (all it does is saves the messages as .eml files). I've tried opening the messages with Lotus Notes and gmail (web interface) and both do not interpret the HTML, for example instead of having a clickable link they have <a href='localhost'>click here</a> Did I make a mistake with the headers?
Here is the code I am using
$to = 'bepusslai#fakeinbox.com';
$from = 'From: tester1#localhost.com';
$subject = 'this is a test';
$message = '<html><head></head><body>Hello. Please follow this link to activate your account.'
."r\n".'<a href="http://localhost/proc.php?uid=45ab3"><img src="images/ActivateButton.gif" alt="activate button" />
</body></html>';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; utf-8' . "\r\n";
$headers .= 'From: testk1#localhost.com' . "\r\n";
mail($to, $subject, $message, $from, $headers);
By the way, I was stuck not having a mail server since WAMP doesn't come with one and I red on another question someone recommended Test Mail Server Tool. I'm open to using a different one because it doesn't seem popular.
If you refer to the docs and examples in the docs, you will see that the From information is not a separate argument to mail() but is included with the additional-headers information.
bool mail ( string $to , string $subject , string $message [, string
$additional_headers [, string $additional_parameters ]] )
Remove your $from argument from the call to mail().
mail($to, $subject, $message, $headers);
Look at this example , it works for me :
<?
//change this to your email.
$to = "m#maaking.com";
$from = "m2#maaking.com";
$subject = "Hello! This is HTML email";
//begin of HTML message
$message = "<html>
<body bgcolor=\"#DCEEFC\">
<center>
<b>Looool!!! I am reciving HTML email......</b> <br>
<font color=\"red\">Thanks dud!</font> <br>
* test.com
</center>
<br><br>*** Now you Can send HTML Email <br> Regards<br>MOhammed Ahmed - Palestine
</body>
</html>";
//end of message
// To send the HTML mail we need to set the Content-type header.
$headers = "MIME-Version: 1.0rn";
$headers .= "Content-type: text/html; charset=iso-8859-1rn";
$headers .= "From: $from\r\n";
//options to send to cc+bcc
//$headers .= "Cc: [email]maa#p-i-s.cXom[/email]";
//$headers .= "Bcc: [email]email#example.cXom[/email]";
// now lets send the email.
mail($to, $subject, $message, $headers);
echo "Message has been sent....!";
?>
I've got Mamp running on my mac and trying to get mail() to work.
This is what I've got to work with.
$to = 'mymail#gmail.com';
$subject = 'The subject!';
$message = 'Hi there!';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= "X-Mailer: PHP/".phpversion();
$headers .= 'From: Test <test#test.com>' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Mail it
if(mail($to, $subject, $message, $headers))
{ print 'success!'; }
else
{ print 'fail!'; }
?>
It just keeps on returning false. Any idea what I'm doing wrong?
Some settings with php/apache I need to check?
if you using your snippet on localhost, put on server and then try.
php mail() function needs to be on sever if you want it to work. on localhost you always get fail!
Try this:
<?php
$Name = "Da Duder"; //senders name
$email = "email#adress.com"; //senders e-mail adress
$recipient = "PersonWhoGetsIt#emailadress.com"; //recipient
$mail_body = "The text for the mail..."; //mail body
$subject = "Subject for reviever"; //subject
$header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields
ini_set('sendmail_from', 'me#domain.com');
mail($recipient, $subject, $mail_body, $header);
?>
http://be.php.net/manual/en/function.mail.php
each line of text may not be bigger than 70 chars and needs to be cut off with a LF (\n)
EDIT: as #brad suggested: SwiftMailer is realy good!