A
A
Abra Kadabra2015-04-06 22:35:02
PHP
Abra Kadabra, 2015-04-06 22:35:02

How to properly implement mail() on free hosting?

Good evening.
I ran into a problem in processing a form to send a message.
I used different free hostings, problem 1 is the same - the letter simply does not arrive, while Denver normally imitates sending.
What I did:
1) I wrote the processing myself.
2) Googled.
3) I took ready-made scripts.
4) Used different postal services.
5) Wrote in support.
This is how the script that I found on the net looks like (because I decided that there may already be errors in mine (hardly))

<?php 
if(isset($_POST['submit'])){
    $to = "[email protected]"; // this is your Email address
    $from = $_POST['email']; // this is the sender's Email address
    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $subject = "Form submission";
    $subject2 = "Copy of your form submission";
    $message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message'];
    $message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];

    $headers = "From:" . $from;
    $headers2 = "From:" . $to;
    mail($to,$subject,$message,$headers);
    mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
    echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
    // You can also use header('Location: thank_you.php'); to redirect to another page.
    }
?>

<!DOCTYPE html>
<html>
<head>
<title>Form submission</title>
</head>
<body>

<form action="" method="post">
First Name: <input type="text" name="first_name"><br>
Last Name: <input type="text" name="last_name"><br>
Email: <input type="text" name="email"><br>
Message:<br><textarea rows="5" name="message" cols="30"></textarea><br>
<input type="submit" name="submit" value="Submit">
</form>

</body>
</html>

I am using byethost.com .
Result 1 - the letter does not arrive.
What did you experience in a similar situation?
How did you solve such a problem?
Do you need hosting setup?
Do you know any suitable ones?
Are there any special settings ? (cpanel doesn't show anything specific at all).
Thank you.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Mikhail Osher, 2015-04-06
@miraage

Don't wait and move to VPS.
// EDIT
Use Swift Mailer , Luke.

S
Supme, 2015-04-06
@Supme

SPF in DNS to register, indicating the hosting IP

6
65536, 2015-04-06
@65536

look at the line in phpinfo, if some kind of soap is written there, then replace $from = $_POST['email']; on $from = soap that is written there;
it may be such a hosting restriction that they do not send from random addresses. $_POST['email'] can be added to reply-to

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question