PHP using SMTP Authentication

My code is not working, getting errors

Page 1 of 1

6 Replies - 3992 Views - Last Post: 16 February 2010 - 08:34 PM Rate Topic: -----

#1 Torijones  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 16-February 10

PHP using SMTP Authentication

Posted 16 February 2010 - 08:00 PM

Hi, all of a sudden my hosting company said I needed SMTP authentication with for my PHP contact forms on my web sites. I have been reading all night to try and get this code right. I know very little about PHP.

Here is the code:

<?php
require_once "Mail.php";
PEAR::Net_SMTP (my hosting company told me to put this here)
$from = "<info@web-design-island.com>";
$to = "<jonzerette@gmail.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "mail.web-design-island.com";
$username = "info@web-design-island.com";
$password = "mypasswordishere";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?> 



Here is the error:
Parse error: syntax error, unexpected T_VARIABLE in /home/lp7lhadb/public_html/web-design-island.com/pricing.php on line 5

I have tried every possible combo with "", '', ";" brackets, etc.

Also, once I get this script to work, how can I add the contact form fields and Bcc to it? Here is my previous PHP script that worked absolutely fine until it went over to SMTP authentication.

<?php

	$emailSubject = 'MY WEB SITE FORM';
	$webMaster = 'info@web-design-island.com';
		
	$nameField = $_POST['name'];
	$emailField = $_POST['email'];
	$phoneField = $_POST['phone'];
	$commentsField = $_POST['comments'];
	$subjectField = $_POST['subject'];
	
$body = <<<EOD
<hr>
SUBJECT: <br> $subjectField <br>
<hr>
NAME: <br> $nameField <br><br>
EMAIL: <br> $emailField <br><br>
PHONE: <br> $phoneField <br><br>
COMMENTS: <br> $commentsField <br>
<hr>
EOD;
	$headers = "From: $emailField\r\n";
	$headers .= 'Bcc: <info@web-design-island.com>' . "\r\n";
 	$headers .= "Content-type: text/html\r\n";
	$success = mail($webMaster, $emailSubject, $body, $headers);
				
	$theResults = <<<EOD

EOD;

Thank you so much for any help or else I will be up all night trying to crack this case.

Tori
echo "$theResults";
?>



Is This A Good Question/Topic? 0
  • +

Replies To: PHP using SMTP Authentication

#2 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5411
  • View blog
  • Posts: 27,423
  • Joined: 10-May 07

Re: PHP using SMTP Authentication

Posted 16 February 2010 - 08:04 PM

Which of the two sets of code is from the file pricing.php?
Was This Post Helpful? 0
  • +
  • -

#3 Torijones  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 16-February 10

Re: PHP using SMTP Authentication

Posted 16 February 2010 - 08:16 PM

View Postno2pencil, on 16 February 2010 - 07:04 PM, said:

Which of the two sets of code is from the file pricing.php?


The first set of code is the new code they want me to use. The second one is the once I used to use.
Thanks.
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5411
  • View blog
  • Posts: 27,423
  • Joined: 10-May 07

Re: PHP using SMTP Authentication

Posted 16 February 2010 - 08:19 PM

Ok, but that doesn't answer the question. Which set of code is giving you the error. Or better yet, if you don't want to answer that... how do you want to proceed? How do you want to address the issue? Are we working on their suggested code, or your problematic code?
Was This Post Helpful? 0
  • +
  • -

#5 Torijones  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 16-February 10

Re: PHP using SMTP Authentication

Posted 16 February 2010 - 08:22 PM

View Postno2pencil, on 16 February 2010 - 07:19 PM, said:

Ok, but that doesn't answer the question. Which set of code is giving you the error. Or better yet, if you don't want to answer that... how do you want to proceed? How do you want to address the issue? Are we working on their suggested code, or your problematic code?


Yes, we are working on the first code - their suggested code. The second one I can no longer use with my hosting company, but want the same type of script for the form fields and a Bcc.

The first code is the issue and I have to get that working.

Thank you.
Was This Post Helpful? 0
  • +
  • -

#6 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5411
  • View blog
  • Posts: 27,423
  • Joined: 10-May 07

Re: PHP using SMTP Authentication

Posted 16 February 2010 - 08:28 PM

If I may... my experience is much more like the code you were using before, & I have provided a Tutorial here at Dream In Code.

I've never worked with PEAR before.
Was This Post Helpful? 0
  • +
  • -

#7 Torijones  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 16-February 10

Re: PHP using SMTP Authentication

Posted 16 February 2010 - 08:34 PM

View Postno2pencil, on 16 February 2010 - 07:28 PM, said:

If I may... my experience is much more like the code you were using before, & I have provided a Tutorial here at Dream In Code.

I've never worked with PEAR before.



Thanks, I will take a look.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1