Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
381 views
in Technique[技术] by (71.8m points)

javascript - Auto email responding

I'm using the below code to submit form information to my email account but i also want it to send a confirmation email to the sender. I like to add this message for automatic response `

Thanks for your interest "name of the sender"!

This is just a quick note to let you know we have received your form and will respond as soon as we can.

Best,

Marvin

` can you check my code how could I add the code and execute it well?
<?php
header('Content-type: application/json');

$status = array(
    'type' => 'success',
    'message' => 'Application Sent!'
);


$name           =   @trim(stripslashes($_POST['name']));
$address        =   @trim(stripslashes($_POST['address']));
$email          =   @trim(stripslashes($_POST['email']));
$mobile         =   @trim(stripslashes($_POST['mobile']));

$email_form = $email;
$email_to = '[email protected]';

$body = '[name]'     . $name     .  "

" .

        '[address]'  . $address  .  "

" .

        '[email]'    . $email    .  "

" .

        '[mobile]'   . $mobile;


mb_language("Japanese");
mb_internal_encoding("UTF-8");
$success = mb_send_mail($email_to, 'Application', $body, 'From: <'.$email_from.'>');

echo json_encode($status);
die; ?>

there is no problem with this code, I just like recoding for the auto-responding email when this form is successfully sent.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to append below code at bottom to send email to the sender as well.

// Email to Sender (Without HTML/CSS)

$sender_email = $email;
$admin_email = '[email protected]';

$message = "Thanks for your interest".$name."

";

$message .= "This is just a quick note to let you know we have received your 
form and will respond as soon as we can.

";

$message .= "Best,

";
$message .= "Marvin

";

mb_language("Japanese");
mb_internal_encoding("UTF-8");
$success2 = mb_send_mail($sender_email, 'Thanks', $message, 'From: 
<'.$admin_email.'>');


// Email to Sender (With HTML/CSS)

$sender_email = $email;
$admin_email = '[email protected]';

$header = "From: ".$admin_email." 
";
$header.= "Content-Type: text/html; charset=iso-8859-1
";

$message = '<html>
    <head>
        <style type="text/css">
            <!--
                .style2 {
                font-size: 11px;
                font-weight: bold;
                text-decoration: none;
                font-family: Verdana, Arial, Helvetica, sans-serif;
                color:#666666;

                }
                .style3 {
                text-decoration: none;
                font-family: Verdana, Arial, Helvetica, sans-serif;
                font-size: 11px;
                color:#666666;
                }
                -->
        </style>
    </head>
    <body>
        <table width="600" border="0" align="center" style="border:#EFEFEF 
5px solid; padding:5px; font-family:Arial, Helvetica, sans-serif; font-
size:11px; color:#666666">
            <tr>
                <td>
                    <table width="100%" border="0" cellpadding="2" 
cellspacing="6">
                        <tr>
                            <td class="style3">Thanks for your interest 
'.$name.'</td>
                        </tr>
                        <tr>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                            <td class="style3">This is just a quick note to 
let you know we have received your 
form and will respond as soon as we can.</td>
                        </tr>
                        <tr>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                            <td class="style3">Best,<br>
                                Marvin
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </body>
</html>';

mb_language("Japanese");
mb_internal_encoding("UTF-8");
$success2 = mb_send_mail($sender_email, 'Thanks', $message, $header);

Hope it helps!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...