G
G
Gleb Batishchev2015-02-07 10:13:56
PHP
Gleb Batishchev, 2015-02-07 10:13:56

How to make simple php handler for feedback form from one field?

The site has a feedback form with the "Phone" field and the send button. I need a PHP handler to send the entered phone number to my mail. How to implement it. I did not find a solution on the Internet - all the proposed scripts use several fields. Tried to remake them - did not work.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
Max Payne, 2015-02-07
@Paladin91

<form method="post">
<input type="text" name="phone">
<input type="submit">
</form>

<?php
if(($_POST['phone']) and (is_numeric($_POST['phone'])) 
mail("[email protected]", "New Phone: ".$_POST['phone'], $_POST['phone']); 
?>

I
IceJOKER, 2015-02-07
@IceJOKER

<?php

$number = $_POST['number']; //по желанию можно фильтровать или регуляркой проверить 
if(!empty($number))
 mail('[email protected]', 'Number from site', $number);

Specially for FanatPHP :
4dbadcba9b.jpgChoke, smart guy!

F
FanatPHP, 2015-02-07
@FanatPHP

I did not find a solution on the Internet - all the proposed scripts use several fields.

This is because you are trying to sit on two chairs at once.
Receiving a form and sending mail are DIFFERENT, unrelated tasks. And we must not lump them together, but do one at a time.
Receiving and sending a form is the most basic thing in PHP. Are you sure that this part is not working out for you at all? I think if you try, you can do it.
Sending mail is another task. practice sending without any form, and look for scripts not for "sending a phone", but simply for sending letters.
And everything will work out for you

H
holfza, 2015-02-07
@holfza

$phone     = $_POST['phone'];

  $subject = "Тема";
  $headers = "Content-Type: text/html; charset=UTF-8\r\n";
  $message = "Текст письма";

   $to = "[email protected]"; 
   $res = mail($to, $subject, $message, $headers );

Well, the form must have an input with the "phone" attribute, and the form action must send a POST to this file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question