Page 1 of 1

[SOLVED] Multiple Recipients = Failed Sent Message ?

Posted: Sat May 19, 2007 5:16 pm
by infinisource
I have the following script running on 2 different hosting providers and 2 different versions of PHP. The first host uses PHP version 4.4.1 and the other uses 5.1.6. I made certain that I downloaded PHP4 for the host that uses 4.4.1 and PHP5 for the other one so that's not the issue.

The host that is running version 5 of PHP works fine, the other one does not. Here's the script.

Code: Select all

<?php
session_start();

switch($_GET['sendit']){

	case 1:
	
	
	if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) {
	
		if(empty($_POST['fullname']) || empty($_POST['youremail']) || empty($_POST['friendsemail']) || empty($_POST['message'])) {
		
			$msg = "<font color=red>Looks like you forgot a field! Your message has not been sent.</font>";
			break;
			
		} else {
      
		     	//Load in the files we'll need
				require_once "lib/Swift.php";
				require_once "lib/Swift/Connection/SMTP.php";
				require_once "lib/Swift/Authenticator/LOGIN.php";
				 
				//Start Swift
					
				$swift =& new Swift(new Swift_Connection_SMTP("hosting.com"));
				$conn =& new Swift_Connection_SMTP("hosting.com");
				$conn->setUsername("username@hosting.com");
				$conn->setPassword("password");
				
				//Create the message
				$message1 =& new Swift_Message("Hey! Check out this website!");

				
				// add your to fields to the message				
				
				$Array = $_POST["friendsemail"];

				$recipients =& new Swift_RecipientList();
								
				foreach($Array as $key => $value) {
				
					$recipients->addTo($value);
				   
				}				 					
				
				$new_message = $_POST["message"] . "\n\nSee you later!" . "\n\n" .$_POST["fullname"];
				stripslashes($new_message);						
				$part1 =& new Swift_Message_Part($new_message);
				$part1->setCharset("iso-8859-2");
				$message1->attach($part1);
				 
				//Now check if Swift actually sends it
				if ($swift->send($message1, $recipients, new Swift_Address($_POST["youremail"], $_POST["fullname"]))) $msg = "<font color=green>Your message has been sent!</font>";
				else $msg="<font color=red>Something went wrong, probably a script failure.  Sorry.</font>";
				
		}
 
   } else {
      
      // Insert your code for showing an error message here
	  $msg = "<font color=red>You provided the wrong code</font>";
	  
   }

	break;

}
?>
The only thing the script produces is the error "Something went wrong, probably a script failure. Sorry." I can't upgrade to PHP5 on this host so that's not going to work and I made sure that the username and password works in Outlook for the swift_mailer account. Is there something wrong with my code or is the hosting provider? Any help would be greatly appreciated.

Thanks,

Paul

Posted: Sat May 19, 2007 5:32 pm
by Chris Corbyn
What version number of Swift do you have? You can get this info either from the VERSION file, or from looking at the comments at the top of the Swift.php file ;)

Next add these lines of code for debug purposes and PM me the output (don't post the output here if you're authenticating since it will contains sensitive data!):

Code: Select all

//Just *after* calling "new Swift( ... );
$swift->log->enable();

// ... snip ... //

//After you've done everything you wanted to do with Swift (send messages etc)
echo "<pre>";
$swift->log->dump();
echo "</pre>";

Posted: Sun May 20, 2007 9:02 am
by Chris Corbyn
FYI, This was a SMTP server/relay denied issue.