Add recieving email adress in contact form - php

I'm working with contact form
This is part where email is being sending
$emailTo = 'myemail#gmail.com';
$subject = 'Wiadomość ze strony Mud';
$sendCopy = trim($_POST['sendCopy']);
$body = "Email: $email \n\nKind of frame: $frame \n\nColor suggestion: $color \n\nInfo about project: $comments";
$headers = 'From: ' . ' <' . $emailTo . '>' . "\r\n" . 'Reply-To: ' . $email;
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=UTF-8\r\n";
mail($emailTo, $subject, $body, $headers);
// set our boolean completion value to TRUE
$emailSent = true;
Form works good everything is fine, except when I get mail and I want IN MY MAILBOX reply email it shows adress of my webserver
It looks like $headers dont work properly, If I'm right this part of code is responsible for reply adres email "'Reply-To: ' . $email;"
(IM NOT GOOD IN PHP)
And my second optional question is how to make stylish email.
I mean for example in my email when it comes to mailbox it shows
Email: dsadas#dsdas.pl
Kind of frame: dasdsa
Color suggestion: dasdsa
Info about project: dasdsa
How can I do it bold, color etc ?
THANK YOU FOR YOUR TIME, CHEERS

Here you go for headers that will allow HTML for email and fix your reply to email:
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-Type: text/html; charset=utf-8" . "\r\n";
$headers .= "From: $emailTo <$emailTo>" . "\r\n";
Remember that there is limited support for email when it comes to CSS, you can see things that can't be used here: http://www.campaignmonitor.com/css/

Related

Can I get responses from an php email form to be bold or different color when received in the email? [duplicate]

How can I send an HTML-formatted email with pictures using PHP?
I want to have a page with some settings and HTML output which is sent via email to an address. What should I do?
The main problem is to attach files. How can I do that?
It is pretty simple. Leave the images on the server and send the PHP + CSS to them...
$to = 'bob#example.com';
$subject = 'Website Change Request';
$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=UTF-8\r\n";
$message = '<p><strong>This is strong text</strong> while this is not.</p>';
mail($to, $subject, $message, $headers);
It is this line that tells the mailer and the recipient that the email contains (hopefully) well-formed HTML that it will need to interpret:
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
Here is the link I got the information from... (link)
You will need security though...
You need to code your HTML content using the absolute path for images. By absolute path, I mean you have to upload the images to a server and in the src attribute of images you have to give the direct path, like this <img src="http://yourdomain.com/images/example.jpg">.
Below is the PHP code for your reference: It’s taken from mail:
<?php
// Multiple recipients
$to = 'aidan#example.com' . ', '; // Note the comma
$to .= 'wez#example.com';
// Subject
$subject = 'Birthday Reminders for August';
// Message
$message = '
<p>Here are the birthdays upcoming in August!</p>
';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
// Additional headers
$headers .= 'To: Mary <mary#example.com>, Kelly <kelly#example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
?>
I have this code and it will run perfectly for my site:
public function forgotpassword($pass, $name, $to)
{
$body = "<table width=100% border=0><tr><td>";
$body .= "<img width=200 src='";
$body .= $this->imageUrl();
$body .= "'></img></td><td style=position:absolute;left:350;top:60;><h2><font color = #346699>PMS Pvt Ltd.</font><h2></td></tr>";
$body .= '<tr><td colspan=2><br/><br/><br/><strong>Dear '.$name.',</strong></td></tr>';
$body .= '<tr><td colspan=2><br/><font size=3>As per Your request we send Your Password.</font><br/><br/>Password is : <b>'.$pass.'</b></td></tr>';
$body .= '<tr><td colspan=2><br/>If you have any questions, please feel free to contact us at:<br/>support#pms.com</td></tr>';
$body .= '<tr><td colspan=2><br/><br/>Best regards,<br>The PMS Team.</td></tr></table>';
$subject = "Forgot Password";
$this->sendmail($body, $to, $subject);
}
Mail function
function sendmail($body, $to, $subject)
{
//require_once 'init.php';
$from = 'testing#gmail.com';
$headersfrom = '';
$headersfrom .= 'MIME-Version: 1.0' . "\r\n";
$headersfrom .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headersfrom .= 'From: ' . $from . ' ' . "\r\n";
mail($to, $subject, $body, $headersfrom);
}
The image URL function is used for if you want to change the image. You have to it change in only one function. I have many mail functions, like for forgot password or create user. Therefore I am using the image URL function. You can directly set the path.
function imageUrl()
{
return "http://" . $_SERVER['SERVER_NAME'] . substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], "/") + 1) . "images/capacity.jpg";
}
Sending an HTML email is not much different from sending normal emails using PHP. What is necessary to add is the content type along the header parameter of the PHP mail() function. Here is an example.
<?php
$to = "toEmail#domain.com";
$subject = "HTML email";
$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>A table as email</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>Fname</td>
<td>Sname</td>
</tr>
</table>
</body>
</html>
";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\b";
$headers .= 'From: name' . "\r\n";
mail($to, $subject, $message, $headers);
?>
You can also check here for more detailed explanations by W3Schools.
You can easily send the email with HTML content via PHP. Use the following script.
<?php
$to = 'user#example.com';
$subject = "Send HTML Email Using PHP";
$htmlContent = '
<html>
<body>
<h1>Send HTML Email Using PHP</h1>
<p>This is a HTMl email using PHP by CodexWorld</p>
</body>
</html>';
// Set content-type header for sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// Additional headers
$headers .= 'From: CodexWorld<info#codexworld.com>' . "\r\n";
$headers .= 'Cc: welcome#example.com' . "\r\n";
$headers .= 'Bcc: welcome2#example.com' . "\r\n";
// Send email
if(mail($to,$subject,$htmlContent,$headers)):
$successMsg = 'Email has sent successfully.';
else:
$errorMsg = 'Email sending fail.';
endif;
?>
Source code and live demo can be found from here - Send Beautiful HTML Email using PHP
The simplest way is probably to just use Zend Framework or any of the other frameworks like CakePHP or Symfony.
You can do it with the standard mail function too, but you'll need a bit more knowledge on how to attach pictures.
Alternatively, just host the images on a server instead of attaching them. Sending HTML mail is documented in the mail() function documentation.
Use PHPMailer.
To send HTML mail, you have to set $mail->isHTML() only, and you can set your body with HTML tags.
Here is a well written tutorial:
How to send mail using PHP
The trick is to know the content id of the image MIME part when building the HTML body part.
It boils down to making the img tag—<img src="cid:entercontentidhere" />
Kronolith.php
Look at the function buildMimeMessage for a working example.

Email reply to multiple email addresses not working

I want that email reply in php should be received at multiple email address. But it is not working for me. I have tried different ways but none of these working for me.
I am trying this header but it is only replying to the last email address.
$to = "recipientemail#address.com";
$subject = "my email subject";
$message = "my email message";
$headers = array();
$headers []= "MIME-Version: 1.0\r\n";
$headers []= "Content-Type: text/html; charset=UTF-8\r\n";
$headers []= "Reply-To: <" . $EmailAddress1 . "> <" . $EmailAddressss2 . ">" . "\r\n" ;
wp_mail($to, $subject, $message, $headers);
I have tried without braces as well but this one is also not working
$headers []= "Reply-To: 1st#address.com,2nd#address.com\r\n";
I do not have much idea about this so little guidance about this will be much appreciated. Thank you!

Sending email with a link inside the body [duplicate]

How can I send an HTML-formatted email with pictures using PHP?
I want to have a page with some settings and HTML output which is sent via email to an address. What should I do?
The main problem is to attach files. How can I do that?
It is pretty simple. Leave the images on the server and send the PHP + CSS to them...
$to = 'bob#example.com';
$subject = 'Website Change Request';
$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=UTF-8\r\n";
$message = '<p><strong>This is strong text</strong> while this is not.</p>';
mail($to, $subject, $message, $headers);
It is this line that tells the mailer and the recipient that the email contains (hopefully) well-formed HTML that it will need to interpret:
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
Here is the link I got the information from... (link)
You will need security though...
You need to code your HTML content using the absolute path for images. By absolute path, I mean you have to upload the images to a server and in the src attribute of images you have to give the direct path, like this <img src="http://yourdomain.com/images/example.jpg">.
Below is the PHP code for your reference: It’s taken from mail:
<?php
// Multiple recipients
$to = 'aidan#example.com' . ', '; // Note the comma
$to .= 'wez#example.com';
// Subject
$subject = 'Birthday Reminders for August';
// Message
$message = '
<p>Here are the birthdays upcoming in August!</p>
';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
// Additional headers
$headers .= 'To: Mary <mary#example.com>, Kelly <kelly#example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
?>
I have this code and it will run perfectly for my site:
public function forgotpassword($pass, $name, $to)
{
$body = "<table width=100% border=0><tr><td>";
$body .= "<img width=200 src='";
$body .= $this->imageUrl();
$body .= "'></img></td><td style=position:absolute;left:350;top:60;><h2><font color = #346699>PMS Pvt Ltd.</font><h2></td></tr>";
$body .= '<tr><td colspan=2><br/><br/><br/><strong>Dear '.$name.',</strong></td></tr>';
$body .= '<tr><td colspan=2><br/><font size=3>As per Your request we send Your Password.</font><br/><br/>Password is : <b>'.$pass.'</b></td></tr>';
$body .= '<tr><td colspan=2><br/>If you have any questions, please feel free to contact us at:<br/>support#pms.com</td></tr>';
$body .= '<tr><td colspan=2><br/><br/>Best regards,<br>The PMS Team.</td></tr></table>';
$subject = "Forgot Password";
$this->sendmail($body, $to, $subject);
}
Mail function
function sendmail($body, $to, $subject)
{
//require_once 'init.php';
$from = 'testing#gmail.com';
$headersfrom = '';
$headersfrom .= 'MIME-Version: 1.0' . "\r\n";
$headersfrom .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headersfrom .= 'From: ' . $from . ' ' . "\r\n";
mail($to, $subject, $body, $headersfrom);
}
The image URL function is used for if you want to change the image. You have to it change in only one function. I have many mail functions, like for forgot password or create user. Therefore I am using the image URL function. You can directly set the path.
function imageUrl()
{
return "http://" . $_SERVER['SERVER_NAME'] . substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], "/") + 1) . "images/capacity.jpg";
}
Sending an HTML email is not much different from sending normal emails using PHP. What is necessary to add is the content type along the header parameter of the PHP mail() function. Here is an example.
<?php
$to = "toEmail#domain.com";
$subject = "HTML email";
$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>A table as email</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>Fname</td>
<td>Sname</td>
</tr>
</table>
</body>
</html>
";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\b";
$headers .= 'From: name' . "\r\n";
mail($to, $subject, $message, $headers);
?>
You can also check here for more detailed explanations by W3Schools.
You can easily send the email with HTML content via PHP. Use the following script.
<?php
$to = 'user#example.com';
$subject = "Send HTML Email Using PHP";
$htmlContent = '
<html>
<body>
<h1>Send HTML Email Using PHP</h1>
<p>This is a HTMl email using PHP by CodexWorld</p>
</body>
</html>';
// Set content-type header for sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// Additional headers
$headers .= 'From: CodexWorld<info#codexworld.com>' . "\r\n";
$headers .= 'Cc: welcome#example.com' . "\r\n";
$headers .= 'Bcc: welcome2#example.com' . "\r\n";
// Send email
if(mail($to,$subject,$htmlContent,$headers)):
$successMsg = 'Email has sent successfully.';
else:
$errorMsg = 'Email sending fail.';
endif;
?>
Source code and live demo can be found from here - Send Beautiful HTML Email using PHP
The simplest way is probably to just use Zend Framework or any of the other frameworks like CakePHP or Symfony.
You can do it with the standard mail function too, but you'll need a bit more knowledge on how to attach pictures.
Alternatively, just host the images on a server instead of attaching them. Sending HTML mail is documented in the mail() function documentation.
Use PHPMailer.
To send HTML mail, you have to set $mail->isHTML() only, and you can set your body with HTML tags.
Here is a well written tutorial:
How to send mail using PHP
The trick is to know the content id of the image MIME part when building the HTML body part.
It boils down to making the img tag—<img src="cid:entercontentidhere" />
Kronolith.php
Look at the function buildMimeMessage for a working example.

Personalised 'To' field when sending large email list using PHP mail and multiple addresses in the Bcc

Im trying to remember a trick i was taught a while back but can not.
Basically, im using PHP mail() in this fashion:
$to = "emailAddress1#domain.com";
$subject = "Welcome to BuildSanctuary";
$messageContent = "Thankyou for registering Bla bla bla";
$message = 'SOME HTML EMAIL STUFF including the $messageContent var';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To:' . "\r\n";
$headers .= 'From: Accounts<accounts#domain.com>' . "\r\n";
$headers .= 'Bcc: emailAddress1#domain.com,emailAddress2#domain.com,emailAddress3#domain.com,emailAddress4#domain.com' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
I got told a while back that there was a way that you could put your own email in the to field, but when the users receive the emails it looks like they were personally sent the email and the to field shows just their email.
Is this possible? Cant think how.
Thanks.

Send HTML in email via PHP

How can I send an HTML-formatted email with pictures using PHP?
I want to have a page with some settings and HTML output which is sent via email to an address. What should I do?
The main problem is to attach files. How can I do that?
It is pretty simple. Leave the images on the server and send the PHP + CSS to them...
$to = 'bob#example.com';
$subject = 'Website Change Request';
$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=UTF-8\r\n";
$message = '<p><strong>This is strong text</strong> while this is not.</p>';
mail($to, $subject, $message, $headers);
It is this line that tells the mailer and the recipient that the email contains (hopefully) well-formed HTML that it will need to interpret:
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
Here is the link I got the information from... (link)
You will need security though...
You need to code your HTML content using the absolute path for images. By absolute path, I mean you have to upload the images to a server and in the src attribute of images you have to give the direct path, like this <img src="http://yourdomain.com/images/example.jpg">.
Below is the PHP code for your reference: It’s taken from mail:
<?php
// Multiple recipients
$to = 'aidan#example.com' . ', '; // Note the comma
$to .= 'wez#example.com';
// Subject
$subject = 'Birthday Reminders for August';
// Message
$message = '
<p>Here are the birthdays upcoming in August!</p>
';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
// Additional headers
$headers .= 'To: Mary <mary#example.com>, Kelly <kelly#example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
?>
I have this code and it will run perfectly for my site:
public function forgotpassword($pass, $name, $to)
{
$body = "<table width=100% border=0><tr><td>";
$body .= "<img width=200 src='";
$body .= $this->imageUrl();
$body .= "'></img></td><td style=position:absolute;left:350;top:60;><h2><font color = #346699>PMS Pvt Ltd.</font><h2></td></tr>";
$body .= '<tr><td colspan=2><br/><br/><br/><strong>Dear '.$name.',</strong></td></tr>';
$body .= '<tr><td colspan=2><br/><font size=3>As per Your request we send Your Password.</font><br/><br/>Password is : <b>'.$pass.'</b></td></tr>';
$body .= '<tr><td colspan=2><br/>If you have any questions, please feel free to contact us at:<br/>support#pms.com</td></tr>';
$body .= '<tr><td colspan=2><br/><br/>Best regards,<br>The PMS Team.</td></tr></table>';
$subject = "Forgot Password";
$this->sendmail($body, $to, $subject);
}
Mail function
function sendmail($body, $to, $subject)
{
//require_once 'init.php';
$from = 'testing#gmail.com';
$headersfrom = '';
$headersfrom .= 'MIME-Version: 1.0' . "\r\n";
$headersfrom .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headersfrom .= 'From: ' . $from . ' ' . "\r\n";
mail($to, $subject, $body, $headersfrom);
}
The image URL function is used for if you want to change the image. You have to it change in only one function. I have many mail functions, like for forgot password or create user. Therefore I am using the image URL function. You can directly set the path.
function imageUrl()
{
return "http://" . $_SERVER['SERVER_NAME'] . substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], "/") + 1) . "images/capacity.jpg";
}
Sending an HTML email is not much different from sending normal emails using PHP. What is necessary to add is the content type along the header parameter of the PHP mail() function. Here is an example.
<?php
$to = "toEmail#domain.com";
$subject = "HTML email";
$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>A table as email</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>Fname</td>
<td>Sname</td>
</tr>
</table>
</body>
</html>
";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\b";
$headers .= 'From: name' . "\r\n";
mail($to, $subject, $message, $headers);
?>
You can also check here for more detailed explanations by W3Schools.
You can easily send the email with HTML content via PHP. Use the following script.
<?php
$to = 'user#example.com';
$subject = "Send HTML Email Using PHP";
$htmlContent = '
<html>
<body>
<h1>Send HTML Email Using PHP</h1>
<p>This is a HTMl email using PHP by CodexWorld</p>
</body>
</html>';
// Set content-type header for sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// Additional headers
$headers .= 'From: CodexWorld<info#codexworld.com>' . "\r\n";
$headers .= 'Cc: welcome#example.com' . "\r\n";
$headers .= 'Bcc: welcome2#example.com' . "\r\n";
// Send email
if(mail($to,$subject,$htmlContent,$headers)):
$successMsg = 'Email has sent successfully.';
else:
$errorMsg = 'Email sending fail.';
endif;
?>
Source code and live demo can be found from here - Send Beautiful HTML Email using PHP
The simplest way is probably to just use Zend Framework or any of the other frameworks like CakePHP or Symfony.
You can do it with the standard mail function too, but you'll need a bit more knowledge on how to attach pictures.
Alternatively, just host the images on a server instead of attaching them. Sending HTML mail is documented in the mail() function documentation.
Use PHPMailer.
To send HTML mail, you have to set $mail->isHTML() only, and you can set your body with HTML tags.
Here is a well written tutorial:
How to send mail using PHP
The trick is to know the content id of the image MIME part when building the HTML body part.
It boils down to making the img tag—<img src="cid:entercontentidhere" />
Kronolith.php
Look at the function buildMimeMessage for a working example.

Categories