How to send a web page by email? The simplest form of sending data by email using HTML and PHP How to send a bookmark by email

One of the most popular functions on the site is the application or order form, the data from which is sent by email to the site owner. As a rule, such forms are simple and consist of two or three fields for data entry. How to create such an order form? This requires the use of language HTML markup and the PHP programming language.

The HTML markup language itself is simple; you just need to figure out how and where to put certain tags. With the PHP programming language, things are a little more complicated.

For a programmer, creating such a form is not difficult, but for an HTML layout designer, some actions may seem difficult.

Create a data submission form in html

The first line will be as follows

This is a very important element of the form. In it we indicate how the data will be transferred and to which file. In this case, everything is transferred POST method file send.php. The program in this file must accordingly receive the data, it will be contained in the post array, and send it to the specified email address.

Let's get back to form. The second line will contain a field for entering your full name. Has the following code:

The form type is text, that is, the user will be able to enter or copy text here from the keyboard. The name parameter contains the name of the form. In this case, it is fio; it is under this name that everything that the user entered in this field will be transmitted. The placeholder parameter specifies what will be written in this field as an explanation.

Next line:

Here, almost everything is the same, but the name for the field is email, and the explanation is that the user enters his email address in this form.

The next line will be the "send" button:

And the last line in the form will be the tag

Now let's put everything together.





Now let's make the fields in the form mandatory. We have the following code:





Create a file that accepts data from the HTML form

This will be a file called send.php

In the file, at the first stage, you need to accept data from the post array. To do this, we create two variables:

$fio = $_POST["fio"];
$email = $_POST["email"];

Variable names in PHP are preceded by a $ sign, and a semicolon is placed at the end of each line. $_POST is an array into which data from the form is sent. In the html form, the sending method is specified as method="post". Thus, two variables are taken from html forms. To protect your site, you need to pass these variables through several filters - php functions.

The first function will convert all the characters that the user will try to add to the form:

In this case, new variables are not created in php, but existing ones are used. What the filter will do is transform the character "<" в "<". Также он поступить с другими символами, встречающимися в html коде.

The second function decodes the URL if the user tries to add it to the form.

$fio = urldecode($fio);
$email = urldecode($email);

With the third function we will remove spaces from the beginning and end of the line, if any:

$fio = trim($fio);
$email = trim($email);

There are other functions that allow you to filter php variables. Their use depends on how concerned you are that an attacker will try to add program code to this html email submission form.

Validation of data transferred from HTML form to PHP file

In order to check whether this code works and whether data is being transferred, you can simply display it on the screen using the echo function:

echo $fio;
echo "
";
echo $email;

The second line here is needed to separate the output of php variables into different lines.

Sending received data from an HTML form to email using PHP

To send data by email, you need to use the mail function in PHP.

mail("to which address to send", "subject of the letter", "Message (body of the letter)","From: from which email the letter is sent \r\n");

For example, you need to send data to the email of the site owner or manager [email protected].

The subject of the letter should be clear, and the message of the letter should contain what the user specified in the HTML form.

mail(" [email protected]", "Application from the site", "Full name:".$fio.". E-mail: ".$email ,"From: [email protected]\r\n");

It is necessary to add a condition that will check whether the form was sent using PHP to the specified email address.

if (mail(" [email protected]", "Order from the site", "Full name:".$fio.". E-mail: ".$email ,"From: [email protected]\r\n"))
{
echo "message sent successfully";
) else (
}

Thus, the program code of the send.php file, which will send the HTML form data to email, will look like this:

$fio = $_POST["fio"];
$email = $_POST["email"];
$fio = htmlspecialchars($fio);
$email = htmlspecialchars($email);
$fio = urldecode($fio);
$email = urldecode($email);
$fio = trim($fio);
$email = trim($email);
//echo $fio;
//echo "
";
//echo $email;
if (mail(" [email protected]", "Application from the site", "Full name:".$fio.". E-mail: ".$email ,"From: [email protected]\r\n"))
( echo "message sent successfully";
) else (
echo "errors occurred while sending the message";
}?>

Three lines to check whether the data is being transferred to the file are commented out. If necessary, they can be removed, since they were needed only for debugging.

We place the HTML and PHP code for submitting the form in one file

In the comments to this article, many people ask the question of how to make sure that both the HTML form and the PHP code for sending data to email are in one file, and not two.

To implement this work, you need to place the HTML code of the form in the send.php file and add a condition that will check for the presence of variables in the POST array (this array is sent from the form). That is, if the variables in the array do not exist, then you need to show the user the form. Otherwise, you need to receive data from the array and send it to the recipient.

Let's see how to change the PHP code in the send.php file:



Application form from the site


//check if variables exist in the POST array
if(!isset($_POST["fio"]) and !isset($_POST["email"]))(
?>





) else (
//show the form
$fio = $_POST["fio"];
$email = $_POST["email"];
$fio = htmlspecialchars($fio);
$email = htmlspecialchars($email);
$fio = urldecode($fio);
$email = urldecode($email);
$fio = trim($fio);
$email = trim($email);
if (mail(" [email protected]", "Application from the site", "Full name:".$fio.". E-mail: ".$email ,"From: [email protected]\r\n"))(
echo "Message sent successfully";
) else (
echo "Errors occurred while sending the message";
}
}
?>

We check the existence of a variable in the POST array with the isset() PHP function. An exclamation mark before this function in a condition means negation. That is, if the variable does not exist, then we need to show our form. If I hadn’t put the exclamation point, the condition would literally mean “if exists, then show the form.” And this is wrong in our case. Naturally, you can rename it to index.php. If you rename the file, do not forget to rename the file name in the line

. The form should link to the same page, for example index.php. I added the page title to the code.

Common errors that occur when submitting a PHP form from a website

The first, probably the most popular mistake, is when you see a blank white page with no messages. This means that you made an error in the page code. You need to enable display of all errors in PHP and then you will see where the error was made. Add to the code:

ini_set("display_errors","On");
error_reporting("E_ALL");

The send.php file must only be run on the server, otherwise the code simply will not work. It is advisable that this is not a local server, since it is not always configured to send data to an external mail server. If you run the code not on the server, then the PHP code will be displayed directly on the page.

Thus, for correct operation, I recommend placing the send.php file on the site hosting. As a rule, everything is already configured there.

Another common mistake is when the “Message sent successfully” notification appears, but the letter does not arrive in the mail. In this case, you need to carefully check the line:

if (mail(" [email protected]", "Order from the site", "Full name:".$fio.". E-mail: ".$email ,"From: [email protected]\r\n"))

Instead of [email protected] there must be an email address to which the letter should be sent, but instead[email protected] must be an existing email for this site. For example, for a website this will be . Only in this case a letter with the data from the form will be sent.

There is a lot of interesting and useful content on the Internet. Sometimes it can be much easier to send a friend a link to interesting information instead of copying it from a site and forwarding it in other ways. How to send a link as conveniently as possible?

Email

Most modern email services support the ability to simply insert a link. That is, you just need to copy it from the address bar of your browser, then paste it into the letter and it will become “clickable”, that is, after clicking on it, the desired page will automatically open.

If you type the address of a site or page manually, the link will not work this way. To fix this, try writing http:// or www at the beginning of the link. That is, instead of site.com you need to write http://site.com or www.site.com After this, the link will be clickable.

You can also attach a link to certain words in the letter. To do this, you need to select them and click “Insert link” on the toolbar, and then indicate the address of the desired page in the window. If your mail supports the use of html tags, then you can insert a link like this: the words to which you attach the link.

Classmates

Before sending a link on Odnoklassniki, you need to download special software that allows you to do this. One such program is GF Tools. It is completely free and very easy to use. You can also simply paste the link text into a message you send to another user. It can also be posted on a wall.

In contact with

You can also insert the link into the status and messages on the wall. In this case, the link will also be “clickable” for all users. When you insert a link to a wall, the site script will automatically show the first image from the page to which the link is given, as well as several lines of text from it.

There are many ways to "cut" a web page.

But Pocket requires the app and a Pocket account. This means that you need to install another application, log in to the service, synchronize, etc. It would be nice if you could do the same using your mailbox.

That's the idea behind EmailThis, which is exactly what its name suggests. With one click, this bookmarklet (or extension,
if you are a Chrome user) will deliver the current web page to your inbox. And like Pocket, it removes all the ads and mobile-unfriendly formatting, leaving you with just easy-to-read text and images. (It also provides the original link below if you want to return to the site.)

Once you've completed the initial setup (in English), using EmailThis is literally a click of a button: Click on the bookmarklet (or extension icon) when you want to send yourself the page you're currently viewing.

Interestingly, the bookmark is also compatible with Android and iOS browsers, but using it requires a little more effort. Android users need to enter "email this" in the address bar, while iOS users need to open their saved bookmarks and tap "Email This".

Of course, many mobile browsers have a “read later” option, which works great. But if you want the page to be delivered to your inbox, this is the best way.

Unfortunately, EmailThis is not compatible with Microsoft Edge, which does not support bookmarklets. If you find a workaround, be sure to let me know in the comments.

I tested the tool with various web pages. It worked great with most of them. I noticed that some of the embedded images were not being "cut", perhaps because they were hosted on a third party. But overall, I found EmailThis to be a quick and easy way to send any web page to your inbox.

And I like this option better than the "read later" options because my inbox duplicates the to-do list functionality. This way, the web content that I consider important is not forgotten or overlooked.

Editor's note: This article was originally published on February 25, 2014 and has been updated today.

What are some ways to send a web page to email?
In various ways, depending on what the author of the question meant.

For example, if you have a program for taking screenshots, you can take a screenshot of an open page and send it as an image to the email of the person you need. In this case, the image will be dead and the links will not work.

I suspect that a more correct answer would be to save the page using standard methods. Click the “file” menu in the browser, then “save as” and save the entire web page. If the person to whom this page is sent has Internet access, he will be able to follow the links from the page, they will be working.

In the first case, it will be easier to open the page if a common image format is selected - bmp, jpg, gif. In the second case, there may be problems with displaying a page saved in one browser but opened in another; it may not be displayed correctly or may not open at all.

Both cases are designed for preservation in an archive, for sending to a person who does not have constant access to the Internet. In this case, it is better to attach it to the letter.

But if a person always has the Internet, why save and send him a page or make an attachment? It is much easier to copy the link of the desired page in the address bar and paste it into the body of the letter.

To do this, you can use specialized online archiving services, for example - Archive.today: archive today

Here you just need to place the URL address of the resource and the system itself will create a zip file and a URL link to a “snapshot” of the web page, which will always be online, even if the original version disappears.

A zip file can be attached to an email, a link to a “snapshot” of a web page can be inserted into the email field, and the whole thing can be sent via email or saved in any other way.

For example, today's version of the Moscow FAQ page (along with a zip file) is available here: archive today

You can also use online services to take screenshots, for example Web-capture: web-capture net

What are some ways to send a web page to email?
In various ways, depending on what the author of the question meant.

For example, if you have a program for taking screenshots, you can take a screenshot of an open page and send it as an image to the email of the person you need. In this case, the image will be dead and the links will not work.

I suspect that a more correct answer would be to save the page using standard methods. Click the “file” menu in the browser, then “save as” and save the entire web page. If the person to whom this page is sent has Internet access, he will be able to follow the links from the page, they will be working.

In the first case, it will be easier to open the page if a common image format is selected - bmp, jpg, gif. In the second case, there may be problems with displaying a page saved in one browser but opened in another; it may not be displayed correctly or may not open at all.

Both cases are designed for preservation in an archive, for sending to a person who does not have constant access to the Internet. In this case, it is better to attach it to the letter.

But if a person always has the Internet, why save and send him a page or make an attachment? It is much easier to copy the link of the desired page in the address bar and paste it into the body of the letter.

To do this, you can use specialized online archiving services, for example - Archive.today: archive today

Here you just need to place the URL address of the resource and the system itself will create a zip file and a URL link to a “snapshot” of the web page, which will always be online, even if the original version disappears.

A zip file can be attached to an email, a link to a “snapshot” of a web page can be inserted into the email field, and the whole thing can be sent via email or saved in any other way.

For example, today's version of the Moscow FAQ page (along with a zip file) is available here: archive today

You can also use online services to take screenshots, for example Web-capture: web-capture net