简体   繁体   中英

Send html form value to e-mail with php

I am stack with my form. I have to send value on e-mail. I don't know php, I know just JS(html, css). I have a very simple file structure, just html, css (a bit JS). I don't have any package manager. I have to do my form with php. -I found example, put php code on the top of my html file. -Added .htaccess file How I understand I need to use Apache as well, or not? I don't have any idea about php - right me please some instruction what I have to do in simple way.

You can use PHPMailer to send emails easily. First you need to know how to get post data in PHP. and then store them as new variables then add them in Mail body to send.

Link for the PHPMailer: https://github.com/PHPMailer/PHPMailer

Tutorial for PHPMailer: https://github.com/PHPMailer/PHPMailer/wiki/Tutorial

You have to provide your email and password details in PHPMailer Library Finally, Your PHP code be like below

<?php
    require 'PHPMailerAutoload.php';
    $name = $_POST['name']; 
    $email = $_POST['email'];
    $mail = new PHPMailer;
    $mail->setFrom('from@example.com', 'Your Name');
    $mail->addAddress($email, 'My Friend');
    $mail->Subject  = 'First PHPMailer Message';
    $mail->Body     = " Hi! $name This is my first e-mail sent through PHPMailer.';
    if(!$mail->send()) {
    echo 'Message was not sent.';
    echo 'Mailer error: ' . $mail->ErrorInfo;
    } else {
    echo 'Message has been sent.';
    }

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