Return to Snippet

Revision: 52380
at October 21, 2011 02:29 by florent


Initial Code

1	<?php
2	    function mail_from() {
3	        $emailaddress = '[email protected]';
4	        return $emailaddress;
5	    }
6	 
7	    function mail_from_name() {
8	        $sendername = "1stWebDesigner.com - Dainis";
9	        return $sendername;
10	    }
11	 
12	    add_filter('wp_mail_from','mail_from');
13	    add_filter('wp_mail_from_name','mail_from_name');
14	?>
1	<html></span></h2>
2	<pre><head>
3	    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
4	</head>
5	<body>
6	    <table style="font-family: Verdana,sans-serif; font-size: 11px; color: #374953; width: 600px;">
7	      <tr>
8	        <td align="left"><a href="<?php bloginfo('url'); ?>" title="MyBlog"><img src="<?php bloginfo('url'); ?>/logo.png" alt="MyBlog" style="border: none;" ></a></td>
9	      </tr>
10	      <tr>
11	        <td>&nbsp;</td>
12	      </tr>
13	      <tr>
14	        <td align="left">Yo, <?php echo $name; ?>.<br />How are you?</td>
15	      </tr>
16	      <tr>
17	        <td>&nbsp;</td>
18	      </tr>
19	      <tr>
20	        <td>I've recieved your message and we'll answer it soon!</td>
21	      </tr>
22	      <tr>
23	        <td>&nbsp;</td>
24	      </tr>
25	      <tr>
26	        <td align="left" style="background-color: #aeaeae; color:#FFF; font-size: 12px; font-weight: bold; padding: 0.5em 1em;">Original Message</td>
27	      </tr>
28	      <tr>
29	        <td><?php echo $message; ?></td>
30	      </tr>
31	      <tr>
32	        <td>&nbsp;</td>
33	      </tr>
34	      <tr>
35	        <td align="center" style="font-size: 10px; border-top: 1px solid #c10000;">
36	            <p><i>Thank you!</i><br /><b>MyBlog</b> - <br /><?php bloginfo('url'); ?></p>
37	        </td>
38	      </tr>
39	    </table>
40	</body>
41	</html>

And we call this function with our contact form:
1	<?php
2	    function contactMail($post) {
3	        $attachments = "";
4	        $subject = "[MyBlog] Contact";
5	        $name = $post["name"];
6	        $email = $post["email"];
7	        $message = $post["message"];
8	        ob_start();
9	            include(TEMPLATEPATH . '/_mails/contact.html');
10	            $message = ob_get_contents();
11	        ob_end_clean();
12	 
13	        $headers = "From: [email protected] 
";
14	        $headers .= "Return-Path: [email protected] 
";
15	        $headers .= "MIME-Version: 1.0
";
16	        $headers .= "Content-Type: text/html; charset=UTF-8
";
17	        $headers .= "BCC: [email protected]
";
18	        //$headers .= "BCC: [email protected]
";
19	        wp_mail( $email, $subject, $message, $headers, $attachments );
20	    }
21	?>

Initial URL


Initial Description


Initial Title
HTML Emails with wp_mail() 

Initial Tags
email, wordpress

Initial Language
PHP