6 Replies - 8863 Views - Last Post: 03 March 2011 - 08:02 AM Rate Topic: -----

#1 cgannon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 26-November 09

Sending email from php using gmail smtp

Posted 03 March 2011 - 07:23 AM

Hi,

I am trying to add some basic email functionality to a project. I have to use the gmail smtp because I want to be able to send it to myself. I get the follwoing errors

Quote

Warning: mail() expects at least 3 parameters, 2 given in C:\xampp2\htdocs\fyp\sendingemail.php on line 51


Quote

Fatal error: Call to a member function send() on a non-object in C:\xampp2\htdocs\fyp\sendingemail.php on line 52


I have aslo had trouble with the following attmepts:
$smtp = Mail::factory('smtp',array ('host' => $host,'port' =>$port,'auth' =>true,'username' =>$username,'password' =>$password));
Mail::factory('smtp',array ($host,$port,$username,$password));


If anyone has any help Thanks!

if (isset($_REQUEST['to']))
			//if "email" is filled out, send email
			 {
			  //send email
			  echo "hi";
			  $from = $_REQUEST['from'] ;
			  $subject = $_REQUEST['subject'] ;
			  $message = $_REQUEST['message'] ;
			  $to = $_REQUEST['to'];
			  
			$host = "ssl://smtp.gmail.com";
			$port = "465";
			$username = "<xxxx.com>";
			$password = "xxxx";
			
				$headers = array ('From' => $from,'Subject' => $subject);
				$smtp = Mail('smtp',array ($host,$port,$username,$password));
				$mail = $smtp->send($to, $headers, $message);

					if (PEAR::isError($mail)) 
					{
					  echo("<p>" . $mail->getMessage() . "</p>");
					}
					else 
					{
					  echo("<p>Message successfully sent!</p>");
					{
			  }
			else
			//if "email" is not filled out, display the form
			//this is where the data and details are taken from
			  {
			  echo "<form method='post' action='sendingemail.php'>
			   To: <input name='to' type='text' />
			  <br />
			  From: <input name='from' type='text' />
			  <br />
			  Subject: <input name='subject' type='text' />
			  <br />
			  Message:
			  <br />
			  <textarea name='message' rows='15' cols='40'>
			  </textarea>
			  <br />
			  <input type='submit'value='Send Email'/>
			  </form>";
			  }

This post has been edited by Dormilich: 03 March 2011 - 07:29 AM
Reason for edit:: please use [code] /* your code source here */ [/code] tags when posting code


Is This A Good Question/Topic? 0
  • +

Replies To: Sending email from php using gmail smtp

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3550
  • View blog
  • Posts: 10,319
  • Joined: 08-June 10

Re: Sending email from php using gmail smtp

Posted 03 March 2011 - 07:31 AM

Quote

$smtp = Mail('smtp',array ($host,$port,$username,$password));

you most certainly meant to create an object here, but only called PHP’s mail() function, which requires 3 parameters and returns you a boolean.


personally, I’d use a Mail library written for PHP 5 (like SwiftMailer) …

This post has been edited by Dormilich: 03 March 2011 - 07:38 AM

Was This Post Helpful? 0
  • +
  • -

#3 cgannon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 26-November 09

Re: Sending email from php using gmail smtp

Posted 03 March 2011 - 07:41 AM

Thanks...so should I keep it like this?
$smtp = Mail::factory('smtp',array ('host' => $host,'port' =>$port,'auth' =>true,'username' =>$username,'password' =>$password));


I get the following error though: Fatal error: Class 'Mail' not found in C:\xampp2\htdocs\fyp\sendingemail.php on line 51...

This post has been edited by Dormilich: 03 March 2011 - 07:43 AM

Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3550
  • View blog
  • Posts: 10,319
  • Joined: 08-June 10

Re: Sending email from php using gmail smtp

Posted 03 March 2011 - 07:43 AM

then you have a problem in setting up PEAR::Mail. did you install it correctly?
Was This Post Helpful? 0
  • +
  • -

#5 cgannon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 26-November 09

Re: Sending email from php using gmail smtp

Posted 03 March 2011 - 07:49 AM

I have PEAR in my directory but I don not know if it is installed or set up etc?
Was This Post Helpful? 0
  • +
  • -

#6 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3550
  • View blog
  • Posts: 10,319
  • Joined: 08-June 10

Re: Sending email from php using gmail smtp

Posted 03 March 2011 - 07:52 AM

did you install the Mail extension? (PEAR is just the repository system, similar to apt-get on Linux)
Was This Post Helpful? 0
  • +
  • -

#7 cgannon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 26-November 09

Re: Sending email from php using gmail smtp

Posted 03 March 2011 - 08:02 AM

No I wouldn't have done anything like that... I was just working on it from a code point of view I didn't know I had to set up extra files. But I do have PEAR in my xampp directory.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1