Hướng dẫn php send mail

Chào mọi người !
Em nhờ mọi người tư vấn giúp em với ạ.
Em có tạo ra 1 form liên hệ như hình:
Làm thế nào để khi có người điền vào thông tin thì nội dung này sẽ chuyển tới mail của em ạ.
Em cũng có tìm hiểu nhưng mãi chưa xong. Nhờ mọi người tư vấn giúp em.
Em cảm ơn !

Bạn thử cái này xem :smile:

https://app.box.com/s/lb16bspifmkfnmu6wjn0yv8ce6q1zb3g

1 Like

Anh xem giúp em đoạn này với ạ, em chạy toàn báo lỗi như trong hình ạ :frowning:
Đây là form ạ:smile:

<form class="form-style-4" action="" method="post">
<label for="field1">
<span>Enter Your Name</span><input type="text" name="field1" required="true">
</label>
<label for="field2">
<span>Email Address</span><input type="email" name="field2" required="true">
</label>
<label for="field3">
<span>Short Subject</span><input type="text" name="field3" required="true">
</label>
<label for="field4">
<span>Message to Us</span><textarea name="field4" onkeyup="adjust_textarea(this)" required="true"></textarea>
</label>
<label>
<span>&nbsp;</span><input type="submit" name="submit" value="Send Letter">
</label>
</form>

Đoạn PHP:

<?php
	if(isset($_POST["submit"]) ){
		include('lib/PHPMailerAutoload.php');
		$mail = new PHPMailer;
		$mail->isSMTP();                                      // Set mailer to use SMTP
		$mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
		$mail->SMTPAuth = true;                               // Enable SMTP authentication
		$mail->Username = '[email protected]';                 // SMTP username
		$mail->Password = '123456789';                           // SMTP password
		$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
		$mail->Port = 587;                                    // TCP port to connect to
		$mail->isHTML(true); 
		$mail->setFrom('a', 'Mailer');
		$mail->addAddress('$_POST["field1"]', 'Tran Van Chau');  
		$mail->Subject = $_POST["field3"];
		$mail->Body    = $_POST["field4"];
		if(!$mail->send()) {
				echo 'Message could not be sent.';
				echo 'Mailer Error: ' . $mail->ErrorInfo;
			} else {
				echo 'Message has been sent';
}
	}
		
?>

Lỗi chỗ mail người nhận đó bạn :smile:

$mail->addAddress('$_POST["field1"]', 'Tran Van Chau');  
                  ^----------------^

Vậy sửa như nào vậy ạ ? Em thay đổi, sửa, … mà không được :frowning:

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?