2014-10-16 2 views
0

여기 내 이메일을 보내는 PHP 코드입니다.PHP 메일 보내기 가끔

<?php 

     class mailer { 
     public function send_request_mail($to, $msg) { 
     $from="[email protected]"; 
     $headers = 'MIME-Version: 1.0' . "\r\n".'Content-type: text/html; charset=iso-8859-1' . "\r\n".'From: ' . $from . "\r\n" . 'Reply-To: ' . $from . "\r\n" . 'X-Mailer: PHP/' . phpversion(); 
     $message = "ip 192.168.0.9:9035"; 
     $subject = "subject"; 
     mail ($to, $subject, $message, $headers); 

      } 
     } 

$mail=new mailer(); 

$mail->send_request_mail("[email protected]", "msg"); 
?> 

가끔 위의 같은 IP 주소를 보내려고 .when (일부 메시지)의 작품, 그것은 나

답변

2

당신이 잘하고있는 희망 fails.help.

PHP는 php.ini 파일에서 시스템에서 이메일을 보내는 방법에 대한 세부 정보를 올바르게 구성해야합니다./etc/디렉토리에있는 php.ini 파일을 열고 [mail function] 섹션을 찾으십시오.

Windows 사용자는 두 개의 지시문을 제공해야합니다. 첫 번째는 이메일 서버 주소를 정의하는 SMTP입니다. 두 번째는 sendmail_from이라고하는데, 이것은 당신의 이메일 주소를 정의합니다.

윈도우의 구성은 다음과 비슷한 모습이 될 것

[mail function] 
; For Win32 only. 
SMTP = smtp.secureserver.net 

; For win32 only 
sendmail_from = [email protected] 

리눅스 사용자들은 PHP가 센드 메일 응용 프로그램의 위치를 ​​알 수 있도록해야합니다. 경로와 원하는 스위치는 sendmail_path 지정 문에 지정해야합니다.

리눅스의 구성은 다음과 비슷한 모습이 될 것

[mail function] 
; For Win32 only. 
SMTP = 

; For win32 only 
sendmail_from = 

; For Unix only 
sendmail_path = /usr/sbin/sendmail -t -i 

PHP는 이메일을 보내 메일() 함수를 사용합니다. 이 함수는받는 사람의 전자 메일 주소, 메시지의 제목 및 실제 메시지를 지정하는 세 가지 필수 인수가 필요합니다. 추가적으로 두 개의 선택적 매개 변수가 있습니다.

mail(to, subject, message, headers, parameters); 

예 :

다음 예는 [email protected]에 복사 [email protected]에 HTML 이메일 메시지를 보내드립니다. 이 프로그램을 사용자로부터 모든 콘텐츠를 받아야하고 전자 메일을 보내야하는 방식으로 코딩 할 수 있습니다.

<html> 
<head> 
<title>Sending HTML email using PHP</title> 
</head> 
<body> 
<?php 
    $to = "[email protected]"; 
    $subject = "This is subject"; 
    $message = "<b>This is HTML message.</b>"; 
    $message .= "<h1>This is headline.</h1>"; 
    $header = "From:[email protected] \r\n"; 
    $header = "Cc:[email protected] \r\n"; 
    $header .= "MIME-Version: 1.0\r\n"; 
    $header .= "Content-type: text/html\r\n"; 
    $retval = mail ($to,$subject,$message,$header); 
    if($retval == true) 
    { 
     echo "Message sent successfully..."; 
    } 
    else 
    { 
     echo "Message could not be sent..."; 
    } 
?> 
</body> 
</html> 

희망이 도움이 될 것입니다 !!! 환호!

긍정적 인 의견을 기다리고 있습니다!

0

mail() 기능을 사용하면 이메일이 스팸 또는 정크 메일 상자에 들어갈 확률이 높기 때문에 PHPMailer과 같은 것을 사용할 수 있습니다. 여기

는 PHPMailer을 이용하여 샘플 코드

<?php 
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->From = '[email protected]'; 
$mail->FromName = '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->WordWrap = 50;         // Set word wrap to 50 characters 
$mail->isHTML(true);         // Set email format to HTML 

$mail->Subject = 'Here is the subject'; 
$mail->Body = 'ip 192.168.0.9:9035'; 

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