简体   繁体   中英

Send email to email submitted in a php form

I would appreciate if someone could point in the right direction when it comes to mail sending with php. I have this contest form http://www.beogradstore.com/mn/contest/main-contest/ and I would like my contest entrants to receive email notifications when they enter the contest AND whenever they receive new entries via referral links. Entries are stored in an SQL table.

What would be the best way to achieve this? Is it using php mail function or something else? Any assistance would be appreciated. Thanks a lot.

I would use the PHP mail() function. Here's an example below of an HTML email:

    $subject = "Subject";
    $msg = '
    <html>
    <body>
    <p>HTML email here</p>
    </body>
    </html>
    ';
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= 'From: Their Name <info@theirdomain.com>' . "\r\n";
    $email = 'info@yourdomain.com';
    if(!mail($email, $subject, $msg, $headers)) {
        // Show error
    }

Use the built-in mail() function to send emails from your PHP app.

For more advanced use cases, including attachements, HTML emails, sending via Gmail, etc. you can use a library like PHPMailer:

http://code.google.com/a/apache-extras.org/p/phpmailer/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM