Reputation: 2126
I am noob with php so pardon my ignorance. I have created php form and it is working fine except one thing. When i get my mail it says that its send from nobody , i have no idea how can i solve this issue so i am asking for little help! Thank you!!!
Here's my code:
<?php
if (isset($_POST['Submit'])) {
if (!empty($_POST['name'])) {
$_POST['name'] = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
if ($_POST['name'] == "") {
$errors .= 'Molimo unesite Vaše ispravno ime.';
}
} else {
$errors .= '<p>Molimo unesite Vaše ime.</p>';
}
if (!empty($_POST['email'])) {
$email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors .= "$email is <strong>NIJE</strong> valjana email adresa.<br/><br/>";
}
} else {
$errors .= '<p>Molimo unesite email adresu.</p>';
}
if ($_POST['message'] != "") {
$_POST['message'] = filter_var($_POST['message'], FILTER_SANITIZE_STRING);
}
if (!$errors) {
$mail_to = '[email protected]';
$subject = 'Kontakt';
$tema = 'Info';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers = 'Od: ' . $_POST['name'] . "\n";
$headers .= 'Email: ' . $_POST['email'] . "\n";
$headers .= "Poruka:\n" . $_POST['message'] . "\n\n";
$user = $_POST['email'];
$poruka ='Vaš kontakt je uspjesno zaprimljen! Odgovorit ću vam u najkraćem mogućem roku. Hvala! Molimo ne odgovarajte na ovu poruku. Ova poruka je automatska.';
mail($mail_to, $subject, $headers, "Content-Type: text/plain; charset=UTF-8;");
mail($user, $tema, $poruka, "Content-Type: text/plain; charset=UTF-8;");
echo "<div style='color:white;margin:0px auto;padding-top:20px;width:290px;background-color:white;font-weight:bold;text-align:center;'><p>Hvala Vam na kontaktu!</p></div>";
} else {
echo '<div class="errors">' . $errors . '<br/></div>';
}
}
?>
And this is how it looks in my yahoo mail:http://www.homepagepays.robertpeic.com/yahoo.png
Upvotes: 0
Views: 85
Reputation: 2126
After little struggle i have managed to solve this with your help:) So i am posting a solution if someone had the same problem. Thx! Notice: $add_headers and inside mail function: [email protected] Here my full code:
if (isset($_POST['Submit'])) {
if (!empty($_POST['name'])) {
$_POST['name'] = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
if ($_POST['name'] == "") {
$errors .= 'Molimo unesite Vaše ispravno ime.';
}
} else {
$errors .= '<p>Molimo unesite Vaše ime.</p>';
}
if (!empty($_POST['email'])) {
$email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors .= "$email is <strong>NIJE</strong> valjana email adresa.<br/><br/>";
}
} else {
$errors .= '<p>Molimo unesite email adresu.</p>';
}
if ($_POST['message'] != "") {
$_POST['message'] = filter_var($_POST['message'], FILTER_SANITIZE_STRING);
}
if (!$errors) {
$mail_to = '[email protected]';
$subject = 'Kontakt';
$tema = 'Info';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= "Content-Type: text/plain; charset=UTF-8" . "\r\n";
$headers .= 'Od: ' . $_POST['name'] . "\n";
$headers .= 'Email: ' . $_POST['email'] . "\n";
$headers .= "Poruka:\n" . $_POST['message'] . "\n\n";
$add_headers = 'From: [email protected]' . "\r\n". "Return-path: [email protected]" . "\r\n";
$user = $_POST['email'];
$poruka ='Vaš kontakt je uspjesno zaprimljen! Odgovorit ću vam u najkraćem mogućem roku. Hvala! Molimo ne odgovarajte na ovu poruku. Ova poruka je automatska.';
mail($mail_to, $subject, $headers, $add_headers, "[email protected]");
mail($user, $tema, $poruka, $add_headers, "[email protected]");
echo "<div style='color:white;margin:0px auto;padding-top:20px;width:290px;background-color:white;font-weight:bold;text-align:center;'><p>Hvala Vam na kontaktu!</p></div>";
} else {
echo '<div class="errors">' . $errors . '<br/></div>';
}
}
?>
This is how it look's NOW in my yahoo mail: http://www.homepagepays.robertpeic.com/yahoo2.png
Upvotes: 0
Reputation: 1422
$from = '[email protected]';
$headers .= "From: " . $from . "\r\n";
Just need an addition to the header.
Upvotes: 2