PHP kullanarak posta göndermek nasıl?

7 Cevap php

I'm using Windows Vista OS. PHP, MySQL as the database and Apache web server.

I want to send notification to those who want to join in my site. But the problem is when I click submit. It doesn't send anything to the email address of the user.

Sizce bunun için en iyi çözüm nedir?

<?php
$to = "recipient@example.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
  echo("<p>Message successfully sent!</p>");
 } else {
  echo("<p>Message delivery failed...</p>");
 }
?>

7 Cevap

Birkaç seçeneğiniz var:

  • Orada mail function inşa, ancak bazı MTA, makinede çalışan kimlik doğrulamasını desteklemez ve ekleri göndermek için çok çalışmak gerekir gerektirir oluyor
  • Eğer Armut şeyler kullanmak isterseniz, Pear Mail paketi var
  • Ben son birkaç yıldır kullanılan ve gerçekten büyük işler PHPMailer class iyi var. Bu güçlü (sadece basit bir arama dahil) projenize dahil etmek çok basit ve kolaydır, ama çünkü bunu seviyorum

Zend_Mail ve Zend Framework E-mail gönderme ile çok düzgün bir iş yok! Zend Framework tamamını kullanmak gerekmez, sadece Zend_Mail kullanabilirsiniz!

25 numaralı portu ayrı bir SMTP sunucusuna erişim gerektiren Armut "Posta" sınıfını kullanın.

Örnek kod aşağıdaki gibidir:

function sendmail($from, $to, $subject, $message, $headers)
{
    if (is_array($to)) {
            $recipients = implode(', ', $to);
    } else {
        $recipients = $to;
    }

    $errorlevel = error_reporting();
    $headers["From"] = $from;
    $headers["To"] = $to;
    $headers["Subject"] = $subject;

    $params = array();
    $params["host"] = "localhost";
    $params["port"] = "25";
    $params["auth"] = false;

    error_reporting($errorlevel & ~E_WARNING);

    $mail_object =& Mail::factory("smtp", $params);
    $res = $mail_object->send($recipients, $headers, $message);

    error_reporting($errorlevel);

    return $res;
}

nb: bu eski kodu - Ben E_WARNING maskelemek zorunda neden şimdi hatırlamıyorum

Bu bir postasunucusu yüklü olması olduğu görünüyor. Apache veya PHP sizin için postaları gönderme değildir. Php bunun için fonksiyonları kaydediyor ama içten gönderme gerçek yapmak için bir posta SMTP sunucusu yapılandırmak zorunda.

Check this post.

Sadece check out "How to Send Email from a PHP Script". Bu posta göndermek için posta işlevini kullanır ve daha çok yerel ve uzak SMTP yapılandırma yapılandırmasını verir.

There are many ways to send email via PHP. Using the internal mail() function is the first if you are not using any framework. I suggest using the Zend_Mail component of the Zend Framework. I've worked with it and it works very well and grants you a nice Object Oriented way to send emails using PHP. But if you have your reasons to use the mail() function, then I think you might need to know these: PHP mail() does not send email itself. It utilizes other tools to send emails. If you are running your application in Unix systems, mail() tries to send the email by using the sendmail program which is commonly installed on most Unix-like systems. On Windows platforms, there is no sendmail installed so PHP will try to send the email using an SMTP server. so you should tell PHP where this SMTP server is and provide it with the username/password of the SMTP server, if there are any. You can do this by editing your PHP configuration file, php.ini. This file is a text-based configuration file that PHP will use when executed. Find your php.ini file and modify these values in this file:

SMTP = localhost
smtp_port = 25
sendmail_from = me@example.com

Lütfen php.ini dosyası nerede olduğunu bilmiyorsanız, info.php gibi, basit bir PHP dosyası oluşturun ve içine bu kodu koyun:

<?php
phpinfo();
?>

Run your page and search for .ini. Now you know where your php.ini file is.

Ben Proje çok iyi belgelerine sahiptir ve kullanımı kolaydır, swiftmailer kitaplığını kullanarak öneriyoruz. Bu varsayılan PHP mail () fonksiyonu lutfen kullanarak çeşitli avantajlar sunuyor.

http://swiftmailer.org/