Send email with PHP from html form on submit with the same script

0 votes

When a user has finished filling out an HTML form and has decided to email the data from the form, I want to send an email using PHP. I want to carry it out using the same script that shows the form-containing web page.

I found this code, but the mail does not send.

<?php 

if (isset($_POST['submit'])) {
    $to = $_POST['email']; 
    $subject = $_POST['name'];
    $message = getRequestURI();
    $from = "zenphoto@example.com";
    $headers = "From:" . $from;

    if (mail($to, $subject, $message, $headers)) {
        echo "Mail Sent.";
    }
    else {
        echo "failed";
    }
}

?>

What is the code to send an email in PHP?

Jul 29 in PHP by Kithuzzz
• 3,660 points
5 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In PHP

0 votes
1 answer

How can I use Sockets.io on the client side and communicate with a PHP based application on the server?

Hello @kartik, For 'long-lived connection' , you can ...READ MORE

answered Aug 24, 2020 in PHP by Niroj
• 82,740 points
1,564 views
0 votes
1 answer

How to get the home directory from a PHP CLI script?

Hello @kartik, You can fetch the value of ...READ MORE

answered Nov 3, 2020 in PHP by Niroj
• 82,740 points
1,232 views
0 votes
0 answers

Send mail using an email account created on Hostinger (PHP)

I am using an email I created ...READ MORE

Jun 7 in PHP by Kichu
• 19,040 points
337 views
0 votes
0 answers

PHP: Inserting Values from the Form into MySQL

I created a user table in MySQL from the ...READ MORE

Jun 7 in PHP by Kichu
• 19,040 points
25 views
0 votes
0 answers

Passing variable from JS to PHP within the same page

I know that PHP is a server-side ...READ MORE

Jun 18 in PHP by narikkadan
• 11,280 points
18 views
0 votes
2 answers

Define a SQL query? What is the difference between SELECT and UPDATE Query? How do you use SQL in SAS?

HI.. SQL is Structured Query Language, which is ...READ MORE

answered Aug 8, 2020 in PHP by anonymous
4,732 views
0 votes
1 answer

Vertically centering text in a div

Try this code: .smallUnitBox { ...READ MORE

answered Sep 3, 2018 in Blockchain by digger
• 26,720 points
270 views
0 votes
1 answer
0 votes
0 answers

Anyone can help me out to understand the semantic of (document.getElementBYId("demo").innerHTML="Hello") ?

Hello guys, Can Someone helps me to find ...READ MORE

Jan 17, 2020 in Web Development by anonymous
• 37,500 points
404 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP