Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用php代码发送电子邮件?_Php_Codeigniter_Email - Fatal编程技术网

如何使用php代码发送电子邮件?

如何使用php代码发送电子邮件?,php,codeigniter,email,Php,Codeigniter,Email,我试图从codeigniter项目中发送一封电子邮件,命令echo$this->email->print_debugger()继续返回以下内容: 220 smtp.gmail.com ESMTP q139sm4099547wmd.2-gsmtp 您好:250-smtp.gmail.com,随时为您服务,[41.228.226.174] 250号35882577 250-8比特 250-STARTTLS 250-增强状态码 250-流水线 250 SMTPUTF8 无法发送AUTH LOGIN命令

我试图从codeigniter项目中发送一封电子邮件,命令
echo$this->email->print_debugger()继续返回以下内容:

220 smtp.gmail.com ESMTP q139sm4099547wmd.2-gsmtp
您好:250-smtp.gmail.com,随时为您服务,[41.228.226.174] 250号35882577 250-8比特 250-STARTTLS 250-增强状态码 250-流水线 250 SMTPUTF8 无法发送AUTH LOGIN命令。错误:530 5.7.0必须 首先发出STARTTLS命令。q139sm4099547wmd.2-gsmtp无法 使用PHP SMTP发送电子邮件。您的服务器可能未配置为发送 使用此方法发送邮件

所以我回去尝试用没有codeigniter的简单php代码发送电子邮件,结果发现最初的问题与codeingiter无关,因为我再次失败。 以下是我的php代码:

<?php
$to       = '**********@gmail.com';
$subject  = 'Testing sendmail.exe';
$message  = 'Hi, you just received an email using sendmail!';
$headers  = 'From: ******@gmail.com' . "\r\n" .
            'MIME-Version: 1.0' . "\r\n" .
            'Content-type: text/html; charset=utf-8';
if(mail($to, $subject, $message, $headers))
    echo "Email sent";
else
    echo "Email sending failed";
?>
我还尝试删除行
sendmail\u path=………

最后是我的sendmail.ini:

; configuration for fake sendmail

; if this file doesn't exist, sendmail.exe will look for the settings in
; the registry, under HKLM\Software\Sendmail

[sendmail]

; you must change mail.mydomain.com to your smtp server,
; or to IIS's "pickup" directory.  (generally C:\Inetpub\mailroot\Pickup)
; emails delivered via IIS's pickup directory cause sendmail to
; run quicker, but you won't get error messages back to the calling
; application.

smtp_server=smtp.gmail.com

; smtp port (normally 25)

smtp_port=25

; SMTPS (SSL) support
;   auto = use SSL for port 465, otherwise try to use TLS
;   ssl  = alway use SSL
;   tls  = always use TLS
;   none = never try to use SSL

smtp_ssl=

; the default domain for this server will be read from the registry
; this will be appended to email addresses when one isn't provided
; if you want to override the value in the registry, uncomment and modify

default_domain=

; log smtp errors to error.log (defaults to same directory as sendmail.exe)
; uncomment to enable logging

error_logfile=error.log

; create debug log as debug.log (defaults to same directory as sendmail.exe)
; uncomment to enable debugging

debug_logfile=debug.log

; if your smtp server requires authentication, modify the following two lines

auth_username=***********@gmail.com
auth_password=*******************

; if your smtp server uses pop3 before smtp authentication, modify the 
; following three lines.  do not enable unless it is required.

pop3_server=
pop3_username=
pop3_password=

; force the sender to always be the following email address
; this will only affect the "MAIL FROM" command, it won't modify 
; the "From: " header of the message content

force_sender=************@gmail.com

; force the sender to always be the following email address
; this will only affect the "RCTP TO" command, it won't modify 
; the "To: " header of the message content

force_recipient=

; sendmail will use your hostname and your default_domain in the ehlo/helo
; smtp greeting.  you can manually set the ehlo/helo name if required

hostname=localhost
任何帮助都将不胜感激,因为我已经花了3天多的时间试图解决这个问题,但都无济于事


编辑:第二个代码确实返回“Email sent”,但我在任何地方都找不到它,甚至在垃圾邮件中也找不到。是的,我已将gmail配置为“允许不太安全的应用程序”

您的电子邮件发送部分是正确的。没问题

如果您通过电子邮件发送邮件,则必须正确配置电子邮件设置

  • 如果XAMPP
  • 如果Wamp
  • 注意:如果您有live server,请将其上载到live。它比配置本地设置和所有设置更容易检查


    您的电子邮件代码是可以的,但如果您使用的是wamp服务器…需要更改以下内容

  • 访问您的电子邮件帐户。单击齿轮工具>设置> 转发和POP/IMAP>IMAP访问。单击“启用IMAP”,然后单击 保存您的更改
  • 运行WAMP服务器。在Apache模块下启用ssl_模块
  • 接下来,在php下启用php_openssl和php_套接字
  • **在
    “C:\wamp\bin\php\php5.5.12\php.ini”
    “C:\wamp\bin\apache\apache2.4.9\bin\php.ini”
    **
  • sendmail\u path=“C:\wamp\sendmail\sendmail.exe-t”

  • 重新启动Wamp服务器

  • 我想它会成功的。

    在config/email.php中,我必须添加


    $config['smtp_crypto']=“tls”

    在本地或live server中,恐怕这并不能解决问题将其加载到live server
    ; configuration for fake sendmail
    
    ; if this file doesn't exist, sendmail.exe will look for the settings in
    ; the registry, under HKLM\Software\Sendmail
    
    [sendmail]
    
    ; you must change mail.mydomain.com to your smtp server,
    ; or to IIS's "pickup" directory.  (generally C:\Inetpub\mailroot\Pickup)
    ; emails delivered via IIS's pickup directory cause sendmail to
    ; run quicker, but you won't get error messages back to the calling
    ; application.
    
    smtp_server=smtp.gmail.com
    
    ; smtp port (normally 25)
    
    smtp_port=25
    
    ; SMTPS (SSL) support
    ;   auto = use SSL for port 465, otherwise try to use TLS
    ;   ssl  = alway use SSL
    ;   tls  = always use TLS
    ;   none = never try to use SSL
    
    smtp_ssl=
    
    ; the default domain for this server will be read from the registry
    ; this will be appended to email addresses when one isn't provided
    ; if you want to override the value in the registry, uncomment and modify
    
    default_domain=
    
    ; log smtp errors to error.log (defaults to same directory as sendmail.exe)
    ; uncomment to enable logging
    
    error_logfile=error.log
    
    ; create debug log as debug.log (defaults to same directory as sendmail.exe)
    ; uncomment to enable debugging
    
    debug_logfile=debug.log
    
    ; if your smtp server requires authentication, modify the following two lines
    
    auth_username=***********@gmail.com
    auth_password=*******************
    
    ; if your smtp server uses pop3 before smtp authentication, modify the 
    ; following three lines.  do not enable unless it is required.
    
    pop3_server=
    pop3_username=
    pop3_password=
    
    ; force the sender to always be the following email address
    ; this will only affect the "MAIL FROM" command, it won't modify 
    ; the "From: " header of the message content
    
    force_sender=************@gmail.com
    
    ; force the sender to always be the following email address
    ; this will only affect the "RCTP TO" command, it won't modify 
    ; the "To: " header of the message content
    
    force_recipient=
    
    ; sendmail will use your hostname and your default_domain in the ehlo/helo
    ; smtp greeting.  you can manually set the ehlo/helo name if required
    
    hostname=localhost