Проблем с php Mail() и SМТP

Можеш да използваш външен SMTP сървър, който е безплатен. Пробвай с този на Gmail, ако не настройката на такъв сървър е проста. Прочети в страницата на клиента.
 
Dizasterr каза:
Можеш да използваш външен SMTP сървър, който е безплатен. Пробвай с този на Gmail, ако не настройката на такъв сървър е проста. Прочети в страницата на клиента.
Ако ползвам този на Gmail какво трябва да направя.
Смисъл в php.ini да добавя хоста на стмп-то така ли ?
Щото и понятие си нямам от СМТП.
Ако може малко по подробничко да обясниш
 
Може да ползваш това
class.smtp.php
Код:
<?php
/**
 * Send messages using a local or remote SMTP server.
 * It supports TLS and SSL crypto.
 * @class Smtp
 * @author wooptoo, http://wooptoo.com
 * @license BSD
 */
class Smtp {
    public $server;
    public $port;
    public $crypto;
    public $user;
    public $pass;

    private $timeout = '45';
    private $localhost = 'localhost';
    private $nl = "\r\n";
    private $conn;

    /**
     * Connect and Auth to server.
     *
     * @param string $server - remote server address or 'localhost'
     * @param int $port
     * @param string $crypto - can be null, ssl, tls
     * @param string $user - optional for localhost server
     * @param string $pass - optional for localhost server
     */
    function __construct($server, $port, $crypto=null, $user=null, $pass=null) {
        $this->server = $server;
        $this->port = $port;
        $this->crypto = $crypto;
        $this->user = $user;
        $this->pass = $pass;

        $this->connect();
        $this->auth();
    }

    /**
     * Connect to server.
     */
    function connect() {
        $this->crypto = strtolower(trim($this->crypto));
        $this->server = strtolower(trim($this->server));

        if($this->crypto == 'ssl')
            $this->server = 'ssl://' . $this->server;
        $this->conn = fsockopen(
            $this->server, $this->port, $errno, $errstr, $this->timeout
        );
        fgets($this->conn);
        return;
    }

    /**
     * Auth.
     */
    function auth() {
        fputs($this->conn, 'HELO ' . $this->localhost . $this->nl);
        fgets($this->conn);
        if($this->crypto == 'tls') {
            fputs($this->conn, 'STARTTLS' . $this->nl);
            fgets($this->conn);
            stream_socket_enable_crypto(
                $this->conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT
            );
            fputs($this->conn, 'HELO ' . $this->localhost . $this->nl);
            fgets($this->conn);
        }
        if($this->server != 'localhost') {
            fputs($this->conn, 'AUTH LOGIN' . $this->nl);
            fgets($this->conn);
            fputs($this->conn, base64_encode($this->user) . $this->nl);
            fgets($this->conn);
            fputs($this->conn, base64_encode($this->pass) . $this->nl);
            fgets($this->conn);
        }
        return;
    }

    /**
     * Send an email.
     *
     * @param string $from
     * @param string $to
     * @param string $subject
     * @param string $message
     * @param string $headers - optional
     */
    function send($from, $to, $subject, $message, $headers=null) {
        fputs($this->conn, 'MAIL FROM: <'. $from .'>'. $this->nl);
        fgets($this->conn);
        fputs($this->conn, 'RCPT TO: <'. $to .'>'. $this->nl);
        fgets($this->conn);
        fputs($this->conn, 'DATA'. $this->nl);
        fgets($this->conn);
        fputs($this->conn,
            'From: '. $from .$this->nl.
            'To: '. $to .$this->nl.
            'Subject: '. $subject .$this->nl.
            $headers .$this->nl.
            $this->nl.
            $message . $this->nl.
            '.' .$this->nl
        );
        fgets($this->conn);
        return;
    }

    /**
     * Quit and disconnect.
     */
    function __destruct() {
        fputs($this->conn, 'QUIT' . $this->nl);
        fgets($this->conn);
        fclose($this->conn);
    }
}

?>
Код:
<?php

include('class.smtp.php');


// $mail = new Smtp(server, port, crypto, user, pass);
// crypto can be: null, tls or ssl
$mail = new Smtp('smtp.gmail.com', '25', 'tls', 'user', 'pass');

// for localhost server no auth/crypto is needed:
// $mail = new Smtp('localhost', '25');

// $mail->send(from, to, subject, body, headers = optional)
$mail->send('x@gmail.com', 'y@gmail.com', 'test mail', 'horay!');

// more emails can be sent on the same connection:
$mail->send('x@gmail.com', 'z@gmail.com', 'test mail 2', 'yay!');

?>
 
Пробвах това, но нищо не се случва.
Нищо не се случва. Презарежда и никакъво съобщение от функцията.
Пробвах и твойта функция. Същото положение и с твоя скрипт.

Добавих и:

error_reporting (E_ALL);

При моя скрипт няма грешки съобщения и т.н.

При твоя:
Warning: stream_socket_enable_crypto() [streams.crypto]: this stream does not support SSL/crypto in C:\web\www\class.smtp.php on line 68

П.с. Апачето ми е no_ssl

Някакви идеи ?
 
$mail = new Smtp('smtp.gmail.com', '25', 'tls', 'user', 'pass');

Тук задал ли си user и парола към твоя gmail ?
 
sylarbg каза:
$mail = new Smtp('smtp.gmail.com', '25', 'tls', 'user', 'pass');

Тук задал ли си user и парола към твоя gmail ?

Да.

Виж пак поста най-отдоло :)
 
Не на 2008 windows съм.

Ся инсталирам апаче с OPEN SSL


П.с. Обаче сега апачето неиска да се стартира.
Не съм барал нищо само го инсталлнах и пак неиска.
Някакви идеи ? Аз попринцип затова ползвах апаче без SSL,
защото неиска да се стартира и незнам от какво.

П.с.2. Оправих го стартира явно е било от конфиг файла :)
Самоче сложих стария ми коф и сега пак изкарва грешката:
Warning: stream_socket_enable_crypto() [streams.crypto]: this stream does not support SSL/crypto in C:\web\www\class.smtp.php on line 68
 
На моя скрипт:

Warning: fsockopen() [function.fsockopen]: unable to connect to tls://smtp.gmail.com:465 (Unable to find the socket transport "tls" - did you forget to enable it when you configured PHP?) in C:\web\www\mails.php on line 17

Warning: fgets(): supplied argument is not a valid stream resource in C:\web\www\mails.php on line 19
 
С много тестове и търсене в гугъл се оправих :)
Мерси все пак
Ще дам точка на sylarbg защото той най много помогна :)
Или поне се опита :?:
 

Back
Горе