Yes, it probably wants a password.

When I want to use SMTP from PHP, I usually use PHPMailer class, which comes with its own SMTP class.

    <?php  
    
    require("class.phpmailer.php");  
    
    $mail = new PHPMailer();  
    
    $mail->IsSMTP(); 
    $mail->Host     = "smtp.streamyx.com"; 
    
    $mail->From     = "xxxx@hotmail.com";  
    
    $mail->AddAddress("xxxx@yahoo.com");  
    
    $mail->Subject  = "My very first php mail";  
    $mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
    $mail->WordWrap = 50; if(!$mail->Send()) {
    echo 'Message was not sent.';
    echo 'Mailer error: ' . $mail->ErrorInfo;
    } else {
    echo 'Message has been sent.';
    }
    ?>

    Message was not sent.Mailer error: The following From address failed: xxxx@hotmail.com

    I'm trying the tutorial given by PHPMailer site and I have this error while running the script. Those addresses are valid accounts.

    I was thinking this error might be caused by the wrong SMTP server,so I called my ISP to confirm that I have the correct SMTP server name and smtp_port.

    Any idea?

      The "From:" address may have to be the same as your email address on the SMTP host, otherwise it might reject it as a spam relay attempt. If that's the case, you can set a separate "Reply-To:" header (with the AddReplyTo() method) so that replies will go there.

        You're not using the authentication, so add

        		$mailer->SMTPAuth = true;
        		$mailer->Username = 'yourISPusername';
        		$mailer->Password = 'yourpassword';

        Hopefully now it'll all work and you don't get an error going on about a language file, which actually has nothing to do with a language file.

          The "From:" address may have to be the same as your email address on the SMTP host, otherwise it might reject it as a spam relay attempt. If that's the case, you can set a separate "Reply-To:" header (with the AddReplyTo() method) so that replies will go there.

          I have thought of that and I tried changing the From address to be the same as my email address on the SMTP host, but it still returned the same error..
          Is it possible to solve this problem by changing my SMTP server ? Maybe to gmail or yahoo?

          You're not using the authentication, so add
          PHP Code:
          $mailer->SMTPAuth = true;
          $mailer->Username = 'yourISPusername';
          $mailer->Password = 'yourpassword';
          Hopefully now it'll all work and you don't get an error going on about a language file, which actually has nothing to do with a language file.

          <?php
          
              $mailer->SMTPAuth = true;
              $mailer->Username = 'myispusername';
              $mailer->Password = 'password'; 
          mail("xxxx@hotmail.com","Hello","Testing");
          ?> 

          I added the authentication above into the script, however it still returned the same error.

          Warning: mail() [function.mail]: SMTP server response: 530 Authentication required in C:\wamp\www\firstmail.php on line 6

            Yeah, the variable name should be $mail and not $mailer - just change it and see how it goes.

            Oh - you're still calling the php mail function - you need to use $mail->send() as it's the object that sends the mail for you and has nothing to do with the in built mail() function.

              Drakla;10878879 wrote:

              Yeah, the variable name should be $mail and not $mailer - just change it and see how it goes.

              Oh - you're still calling the php mail function - you need to use $mail->send() as it's the object that sends the mail for you and has nothing to do with the in built mail() function.

              I will try that out. One more thing, as in the php.ini file. the smtp_port is port 25, but my ISP is blocking that port. To be able to send email from php, do I need to perform port-forwarding on port 25?

              Thank you for replying.

                Does your ISP allow smtp to use a different port, like yahoo uses 587 as an alternative. If so then just set it with $mail->Port = 587;

                This is actually an extension to the phpmailer class that I use for testing - you might be able to pick a few bones out

                <?php
                /**
                *	Template class extension of phpmailer that will allow easy global modding to a
                *	testing smtp mail server, or just outputting the mail
                *
                *	@version 1.3.1
                */
                
                /**  */
                require_once(LIB.'phpmailer/class.phpmailer.php');
                	/**  */
                require_once(CONFIG.'config.mailsystem.php');
                
                
                
                /**
                *
                */
                
                class DMPhpMailer extends PHPMailer
                {
                		/** @var bool whether to output when Send() is called */
                	var $outputNotSend = DMMAILER_OUTPUT_NO_SEND;
                
                	/** @var bool whether to use a different mail server */
                var $useDebugServer = DMMAILER_USE_DEBUG_SERVER;
                
                
                	/**
                	*	Constructor
                	*/
                
                function DMPhpMailer()
                {
                	//parent::PHPMailer();	// parent class has no constructor
                }
                
                
                	/**
                	*	Sets up parameters for a testing debug server
                	*/
                
                function set_debug_server()
                {
                	$this->isSMTP();
                //*
                	$this->Host = 'smtp.mail.yahoo.co.uk';
                	$this->Port = 587;	// yahoo optional, necessary on
                
                	$this->FromName = "Drakla's Test Server";
                	$this->From		= 'mytestaccount@yahoo.co.uk';
                	$this->Sender	= $this->From;
                
                	$this->SMTPAuth = true;
                	$this->Username = 'testingusername';
                	$this->Password = 'testingpassword';
                	//*/
                }
                
                
                	/**
                	*
                	*	@return bool
                	*/
                
                function send()
                {
                	if ($this->outputNotSend)
                	{
                		$toList = array();
                		foreach ($this->to as $to)
                		{
                			$toList[] = $to[0];
                		}
                		$toList = implode('&gt; &lt;', $toList);
                
                		echo '<strong>FROM:</strong> "'.$this->FromName.'" &lt;'.$this->From.'&gt;<br />';
                		echo '<strong>TO:</strong> &lt;'.$toList.'&gt;<br />';
                
                
                		echo '<strong>SUBJECT</strong>: ' . $this->Subject . '<hr /><strong>Body:</strong><br />';
                
                		if ($this->ContentType == "text/html")
                		{
                			echo $this->Body . '<hr /><strong>Alt Body:</strong><br />' .
                			nl2br($this->AltBody) . '<hr />';
                		}
                		else
                		{
                			echo nl2br($this->Body) . '<hr /><strong>Alt Body:</strong><br />' .
                			nl2br($this->AltBody) . '<hr />';
                		}
                
                		return true;
                	}
                
                		// is debug server in use ?
                
                	if ($this->useDebugServer)
                	{
                		$this->set_debug_server();
                	}
                
                	return parent::Send();
                }
                }
                ?>

                  I have double checked everything I have, but still I couldn't get things done.I'm using WAMPServer2.0, therefore I would like to know whether WAMPServer 2.0 is capable of sending email? Does it come with mail server?

                  Regards,

                  Anise

                    I am able to send email out by using phpmailer class now.
                    Thanks to Weedpacket, NogDog and Drakla. 🙂

                      Write a Reply...