2016-08-12 3 views
-2

코드를 사용하는 사이트에서 mailid가 필요합니까? 보낸 메일을 보여주고 있지만 코드에 언급 된 mailid에는 아무 것도 보내지 않습니다. 이메일을 보낸 사람이 누구인지 의심 스럽습니다. 그게 내 도메인에 ID를 만들 수 있습니까?PHP 코드로 메일 보내기

$msg=" ".$a." ".$b." ".$c." ".$d." ".$e; 
$to="[email protected]"; 
$sub=$a; 
$msg = wordwrap($msg, 70); 
#echo $msg; 

$r=mail($to,$sub,$msg); 

    if($r== true) { 
echo"<script>alert('mailsent');</script>"; 
    }else { 
     echo"<script>alert('failure');</script>"; 
    } 

내가 사용한 코드 : 이메일을 보내는 메일()를 사용하여

the code i hav used

+0

"이메일 주소"는 무엇이라고 생각하십니까? 이 질문은 의미가 없습니다. –

+0

스택 오버플로에 오신 것을 환영합니다! [코드를 이미지로 게시하지 마십시오.] (// meta.stackoverflow.com/q/285551) – FrankerZ

+0

[PHP 메일 양식이 전자 메일 보내기를 완료하지 못했습니다] (http : // stackoverflow. com/questions/24644436/php-mail-form-doesnt-complete-sending-e-mail) – FrankerZ

답변

1

기껏 당신이 신뢰할 수없는 이메일이 실제로 전송되는 경우 알지 못하거나했습니다 싫어한다 메일을 전달하는 헤더가 발견되면 전달되는 기회가 증가합니다.

$headers = "From: $email\r\n"; 
$headers .= "Reply-To: $email\r\n"; 
$headers .= "MIME-Version: 1.0\r\n"; 
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 

if(mail($to, $sub, $msg, $headers)){ 
    echo "<p>Email Sent</p>"; 
} 

더 나은 방법이 phpmailer 사용하는 것입니다 - 여기 https://github.com/PHPMailer/PHPMailer

이메일을 보내 자신의 샘플입니다

require 'PHPMailerAutoload.php'; 

$mail = new PHPMailer; 

//$mail->SMTPDebug = 3;        // Enable verbose debug output 

$mail->isSMTP();          // Set mailer to use SMTP 
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers 
$mail->SMTPAuth = true;        // Enable SMTP authentication 
$mail->Username = '[email protected]';     // SMTP username 
$mail->Password = 'secret';       // SMTP password 
$mail->SMTPSecure = 'tls';       // Enable TLS encryption, `ssl` also accepted 
$mail->Port = 587;         // TCP port to connect to 

$mail->setFrom('[email protected]', 'Mailer'); 
$mail->addAddress('[email protected]', 'Joe User');  // Add a recipient 
$mail->addAddress('[email protected]');    // Name is optional 
$mail->addReplyTo('[email protected]', 'Information'); 
$mail->addCC('[email protected]'); 
$mail->addBCC('[email protected]'); 

$mail->addAttachment('/var/tmp/file.tar.gz');   // Add attachments 
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name 
$mail->isHTML(true);         // Set email format to HTML 

$mail->Subject = 'Here is the subject'; 
$mail->Body = 'This is the HTML message body <b>in bold!</b>'; 
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; 

if(!$mail->send()) { 
    echo 'Message could not be sent.'; 
    echo 'Mailer Error: ' . $mail->ErrorInfo; 
} else { 
    echo 'Message has been sent'; 
} 

PHPMailer는 매우 유연하고 아주 작은 옵션을 사용할 수 있습니다, 그것은 또한 할 수있다 SMTP를 사용하도록 구성된 경우 인증 된 계정에서 전자 메일을 보내거나 SendGrid와 같은 타사 전자 메일 서비스를 사용하여 전자 메일을 배달 및 모니터링 할 수 있습니다.