The PHP mail function can be used to send the email with PHP. This is useful if you want to implement a contact form on the website. With inbox, PHP, emails can be sent via a simple PHP script. In this tutorial, you will learn how to send an email with PHP and test the PHP mail function.
- What do you need?
- Step 1 Create a new PHP file
- Step 2 – Edit the PHP file
- Step 3 – Run the script Result
What do you need?
Before starting this step, you will need the following:
- Accessing your website hosting account
- The PHP mail function in
Step 1 Create a new PHP file
Firstly, you need to create a PHP file for a website hosting account. Your PHP file must be available via domain name, so it must be placed in the public_html folder. To create the file, you can use the file manager or an FTP client. Testmail.php filename.
Step 2 – Edit the PHP file
Now put the following code in the testmail.php file:
The first two lines, which gives the opportunity for the error message you can see if the script has an error, and it works.
- From – the Sender’s email address. Many website hosting providers do not allow the use of email addresses, by chance, here you need to log in. Email addresses created for your domain name in this area, allow you to get the email sent.
- To – recipient’s email address. How you write for one of these testing purposes can be your email.
- Subject – the subject of the message.
- Message – the content of email messages.
- Headers – in Each card there are themes. They contain important information like your email address.
- Mail (to, subject, message, headers) is a PHP function that executes email address. Your something to change this line.
- Echo “the email message has been sent.” – Choosing PHP echo displays a message on the screen, so the script succeeds.
Step 3 – Run the script
If (as recommended) you entered a public_html directory script, now when you run the script, enter yourdomainname/testmail.php. If you see a message that an email has been sent to your browser, it means that the email has been sent successfully, and you can check your email (don’t forget to check the SPAM / Trash folder electronic).
If you find any error, please enter all details correctly. If the error is displayed in your browser, you can try checking an account error_log file. If you are unsure how to check the file is check this tutorial, the error logs.
Now you know that how to send an email using PHP. Despite the fact that this tutorial will go to testing with the same syntax it can be used for developing a contact form on your website. However, if you need a script, more extra for sending an email using PHP, to test the PHPMailer project. It supports built-in SMTP, comprehensive error_logs from 47 languages, and many other useful features.
for website maintenance service contact us.