Problem z wysyłaniem mail poprzez formularz PHP

0

Witam

Przepraszam, jeśli moje pytanie jest dość trywialne jednak mam problem z wysyłaniem maili z formularza PHP.

Strona stoi na hostingu OVH i dla strony stworzylem przykładową skrzynkę Webmail.

Wpisałem nazwę skrzynki webmail do swojego formularza PHP np. [email protected]

Chce aby maile wysyłać na ten adres a one dalej przekierowywane są przez OVH na inne adresy email.

Jeden z adresów email jest na wp.pl i otrzymuje następujący błąd

"550 BLAD SPF - zobacz strone
/ SPF Error: Od nadawcow wymagamy poprawnych wpisow SPF / Senders are
required to provide correct SPF records "

Mój formularz PHP wygląda następująco:

<?php

$name = ($_GET['name']) ? $_GET['name'] : $_POST['name'];
$email = ($_GET['email']) ?$_GET['email'] : $_POST['email'];
$phone = ($_GET['phone']) ?$_GET['phone'] : $_POST['phone'];
$comment = ($_GET['comment']) ?$_GET['comment'] : $_POST['comment'];

//flag to indicate which method it uses. If POST set it to 1

if ($_POST) 
	$post=1;

//Simple server side validation for POST data, of course, you should validate the email
if (!$name) 
	$errors[count($errors)] = 'Proszę podać swoje imie i nazwisko.';
if (!$email) 
	$errors[count($errors)] = 'Proszę podać swój adres email.'; 
if (!$phone) 
	$errors[count($errors)] = 'Proszę podać swój telefon.'; 
if (!$comment) 
	$errors[count($errors)] = 'Proszę wpisać swoją wiadomość.'; 

//if the errors array is empty, send the mail
if (!$errors) {

	//recipient - replace your email here
	$to = '[email protected]';
	
	//sender - from the form
	$from = $name . ' <' . $email . '>';
	
	//subject and the html message
	$subject = 'Wiadomość z formularza Swierkowy Raj od ' . $name;	
	
	$message = '<html><body>';
	$message .= '
		<table border="1" style="width: 100%; border-spacing: 1px; border-style: solid; border-collapse:collapse;">
		  <tr>
			<th colspan="2" style="height: 50px; padding: 15px;"><H1>Wiadomość z formularza Swierkowy Raj od: ' .$name.'</H1></th>
		  </tr>
		  <tr>
			<td width="20%" style="height: 50px; padding: 5px;"><b>Imię i Nazwisko klienta: </b></td>
			<td width="80%" style="height: 50px; padding: 5px; text-align: justify; text-justify: inter-word;">' . $name . '</td>
		  </tr>
		  <tr>
			<td width="20%" style="height: 50px; padding: 5px;"><b>Numer telefonu: </b></td>
			<td width="80%" style="height: 50px; padding: 5px; text-align: justify; text-justify: inter-word;">' . $phone . '</td>
		  </tr>
		  <tr>
			<td width="20%" style="height: 50px; padding: 5px;"><b>Adres e-mail: </b></td>
			<td width="80%" style="height: 50px; padding: 5px; text-align: justify; text-justify: inter-word;">' . $email . '</td>
		  </tr>
		  <tr>
			<td width="20%" style="height: 50px; padding: 5px;"><b>Treść wiadomość: </b></td>
			<td width="80%" style="height: 50px; padding: 5px; text-align: justify; text-justify: inter-word;">' . nl2br($comment) . '</td>
		  </tr>
		</table>';
	$message .= '</body></html>';

	//send the mail
	$result = sendmail($to, $subject, $message,$from);
	
	//if POST was used, display the message straight away
	if ($_POST) {
		if ($result) 
			echo 'Dziękujemy! Odpiszemy najszybciej jak to będzie możliwe.';
		else 
			echo 'Przepraszamy! Coś poszło nie tak. Spróbuj później';
		
	//else if GET was used, return the boolean value so that 
	//ajax script can react accordingly
	//1 means success, 0 means failed
	} 
	else {
		echo $result;	
	}

//if the errors array has values
} 
else {
	//display the errors message
	for ($i=0; $i<count($errors); $i++) echo $errors[$i] . '<br/>';
		echo '<a href="index.html">Powrót</a>';
	exit;
}


//Simple mail function with HTML header
function sendmail($to, $subject, $message, $headers) {
	
	$headers = "MIME-Version: 1.0" . "\r\n";
	$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
	$headers .= 'From: ' . strip_tags($from) . "\r\n";
	$headers .= "Reply-To: ". strip_tags($from) . "\r\n";
	
	$result = mail($to,$subject,$message,$headers);
	
	if ($result) 
		return 1;
	else 
		return 0;
}

?>

Wydaje mi się, że robię coś nie tak w funkcji mail. Również dodatkowo jak wyślę wiadomość i dam Reply to nie wybiera mi adresy Reply To.

Bardzo proszę o pomoc

0

jak chcesz przekierowanie lub kilka adresów to najlepiej użyć SMTP, nie wiem czy zwykłe sendmail wystarczy, zobacz sobie ja dodawałem działające przykłady na końcu:
Skrypty do PHP

0

Użyj phpmailera albo swiftmailera

0

Jeszcze nie powstał temat na tym forum, gdzie przy użyciu funkcji mail w temacie wątku nie pojawiłoby się słowo problem.

Użyj jakiegoś gotowego mailera (SwiftMailer/PHPMailer).

0

Użycie SwiftMailer / PHPMailer nie rozwiąże Twojego problemu. Problem występuje wtedy, kiedy na SMTP logujesz się jako np. [email protected] a wiadomość próbujesz wysłać z polem FROM innym, np. [email protected] czy nawet [email protected].

Ustaw pole FROM na takie z jakiego rzeczywiście wysyłasz i powinno być wszystko w porządku ;) Najwyżej w treści wiadomości wpisz adres na który powinna zostać wysłana odpowiedź. Na ten moment nie znam lepszego rozwiązania.

0

Dzięki chłopaki ale problemem nie była sama biblioteka mail a sposób w jaki ustawione były headers dla niej.

Tak jak na samym końcu napisał kolega, po dodaniu odpowiedniego pola FROM i innych pól konfiguracyjnych, wszystko wygląda tak jak chciałem :) Dziękuję!

	ini_set("SMTP", "address.pl");
	ini_set("sendmail_from", "[email protected]");

	
	$headers  = "From: Biuro < [email protected] >\n";
	$headers .= "Cc: Biuro < [email protected] >\n";
	$headers .= "X-Sender:Biuro  < [email protected] >\n";
	$headers .= 'X-Mailer: PHP/' . phpversion();
	$headers .= "X-Priority: 1\n"; // Urgent message!
	$headers .= "Return-Path: [email protected] \n"; // Return path for errors
	$headers .= "MIME-Version: 1.0\r\n";
	$headers .= "Content-Type: text/html; charset=utf-8\n";
	

Nie ma potrzeby podmieniania biblioteki na XMAILER czy SWIFTMAIL jak działą bardzo podstawowa z nich. Po co używać tarana do otwarcia słomianych drzwi.

1

PhpMailer mimo wszystko jest wygodniejszy, nie trzeba kleić stringów by dodać wielu odbiorców itp. itd. Nauka takowej biblioteki też nie pójdzie na marne. Dodatkowo niektóre serwery blokują funkcję mail, a oto pierwszy z brzegu przykład
http://forum.php.pl/php_Serwery_nazwapl_blokuja_funkcje_mail_i_co_teraz_t255423.html
Tu masz też więcej wyjaśnień:
https://hostit.pl/blog/458,dbaj-o-reputacje-swojej-poczty.html

1 użytkowników online, w tym zalogowanych: 0, gości: 1