[SOLVED]sc_mail_send multiple addresses in CC - doesn't work

When I try to send an e-mail with CC: to more than one person I get an error:

Fatal error: Uncaught exception 'Swift_RfcComplianceException' with message 'Address in mailbox given [kornel@someserver1.es, kornel@someserver1.com] does not comply with RFC 2822, 3.6.2.' in /opt/NetMake/v7/wwwroot/scriptcase/prod/third/swift/classes/Swift/Mime/Headers/MailboxHeader.php:308 Stack trace: #0 /opt/NetMake/v7/wwwroot/scriptcase/prod/third/swift/classes/Swift/Mime/Headers/MailboxHeader.php(238): Swift_Mime_Headers_MailboxHeader->_assertValidAddress('kornel@server.e...') #1 /opt/NetMake/v7/wwwroot/scriptcase/prod/third/swift/classes/Swift/Mime/Headers/MailboxHeader.php(96): Swift_Mime_Headers_MailboxHeader->normalizeMailboxes(Array) #2 /opt/NetMake/v7/wwwroot/scriptcase/prod/third/swift/classes/Swift/Mime/Headers/MailboxHeader.php(60): Swift_Mime_Headers_MailboxHeader->setNameAddresses(Array) #3 /opt/NetMake/v7/wwwroot/scriptcase/prod/third/swift/classes/Swift/Mime/SimpleHeaderFactory.php(60): Swift_Mime_Headers_MailboxHeader->setFieldBodyModel(Array) #4 /opt/NetMake/v7/wwwroot/scriptcase/prod/third/swift/classes/Swift/ in /opt/NetMake/v7/wwwroot/scriptcase/prod/third/swift/classes/Swift/Mime/Headers/MailboxHeader.php on line 308

When I put on CC: only one address all works well.
As far as I know you can put many addresses in CC: field

Have you tried to separate with a ‘;’ ?

Doesn’t work, but now Swift can’t see address at all:

[…] Swift_Mime_Headers_MailboxHeader->_assertValidAddress(’’) […]

I think SC make something with this variable…
I don’t think it’s Swifts problem. I haven’t been using Swift for some time but I don’t remember it doing such things.

Hello,

Issue reported to our team.

regards,
Bernhard Bernsmann

Hey bartho,
To be more precise
I was putting a code like this below into a library (Programming->Libraries) and including it normally (by selecting it).
Then it didn’t work correctly.
Which means it didn’t want to take CC addresses correctly - the rest is OK.
But when I take identical code and put it eg. in onApplicationInit Event it works 100%!
What’s more when I click “generate app” and then without exiting SC remove the function from onApplicationInit (so it is called from library) it still work until I turn the Apache server off.

//Settings
[mail_smtp_server] = 'myserver.com';                  // SMTP server name or IP address
[mail_smtp_user]   = 'username';                       // SMTP user name
[mail_smtp_pass]   = 'pass';                              // SMTP password
[mail_from]        = 'name@myserver.com';          // From email
[mail_format]      = 'H';                                    // Message format: (T)ext or (H)tml
[mail_copies_type] = 'CCC';					//CCC (means normal CC) and BBC
[mail_port]		   = '465';
[mail_security]	   = 'S';

[mail_footer]	   = '<br>-------------------------------------<br>
This is automatically generated message. Do not reply.<br>
 -------------------------------------<br>';

//Send a system message - you need to give as a parametes a subject and a message only
function my_sys_mail($mail_subject, $mail_message)
	{
		$mail_smtp_server 	= [mail_smtp_server];
		$mail_smtp_user  	= [mail_smtp_user];
		$mail_smtp_pass  	= [mail_smtp_pass];
		$mail_from                	= [mail_from];
		$mail_format       	= [mail_format];
		$mail_copies_type  	= [mail_copies_type];
		$mail_port		  	= [mail_port];
		$mail_security		= [mail_security];
		
		$mail_message  .= [mail_footer];
		$mail_subject 	= "System ".date('Y-m-d H:i:s')." ".$mail_subject;

	//setting mail addr of logged in user (should be in globals)
		$mail_to = [glo_user_emailaddr];

	//finding out list of users to send a copy to
		$sql_chk_recipient = "SELECT GROUP_CONCAT(email SEPARATOR '; ') FROM recipient WHERE something";
		sc_lookup(rs1, $sql_chk_managers);
		$mail_copy_to = {rs1[0][0]};

				
	// Send email
		sc_mail_send($mail_smtp_server,
					 $mail_smtp_user,
					 $mail_smtp_pass,
					 $mail_from,
					 $mail_to,
					 $mail_subject,
					 $mail_message,
					 $mail_format,
				 	 $mail_copy_to,
					 $mail_copies_type,
					 $mail_port,
					 $mail_security,
					 '');

	}

Update:

I’ve just found out that when I include this code using sc_include() function it works correctly.

Hello,

Was the missing sc_include() causing the issue? Or was there something else?

regards,
Bernhard Bernsmann

I think so.
It was freaking out only when I included the library by selecting it in Libraries.

Hi

I am using sc_mail_send function. It is working fine in my Dev environment. However in my same laptop if I deploy; I am getting the following error.

Fatal error: Uncaught exception ‘Swift_TransportException’ with message ‘Expected response code 250 but got code “501”, with message "501 HELO requires valid address "’ in C:\xampp\htdocs\demo_lib\prod hird\swift\classes\Swift\Transport\AbstractSmtpTransport.php:422 Stack trace: #0 C:\xampp\htdocs\demo_lib\prod hird\swift\classes\Swift\Transport\AbstractSmtpTransport.php(306): Swift_Transport_AbstractSmtpTransport->_assertResponseCode(‘501 HELO requir…’, Array) #1 C:\xampp\htdocs\demo_lib\prod hird\swift\classes\Swift\Transport\EsmtpTransport.php(224): Swift_Transport_AbstractSmtpTransport->executeCommand(‘HELO [::1]??’, Array, Array) #2 C:\xampp\htdocs\demo_lib\prod hird\swift\classes\Swift\Transport\AbstractSmtpTransport.php(323): Swift_Transport_EsmtpTransport->executeCommand(‘HELO [::1]??’, Array) #3 C:\xampp\htdocs\demo_lib\prod hird\swift\classes\Swift\Transport\EsmtpTransport.php(272): Swift_Transport_AbstractSmtpTransport->_doHeloCommand() #4 C:\xampp\htdocs\demo_lib\prod hird\swift\classes\Swift\Tr in C:\xampp\htdocs\demo_lib\prod hird\swift\classes\Swift\Transport\AbstractSmtpTransport.php on line 422

Any idea what is going on here?

I am using SC 7.x in Windows 7 64 bit OS.

Regards
Narayanan

Expected response code 250 but got code “501”, with message "501 HELO requires valid address "’ in …

So I guess you have an invalid email address in your code.

Some smtp server require a correct HELO as aducom already said. Without that you cant send a mail.

Hi Albert Drent,

Thank you. That problem has gone not sure how though. Now I am getting the below error. Please note that same smtp settings working very fine when I run from my local dev environment. When I deploy to Production then I am getting this issue. The production is the place actually my SMTP server is there.

I tried with the ports (25 and also SSL port number given by the knolwegebase of my production hosting environment).

Fatal error: Uncaught exception ‘Swift_TransportException’ with message ‘Connection could not be established with host smtpout.secureserver.net [Connection refused #111]’ in /home/content/88/10464488/html/demo/_lib/prod/third/swift/classes/Swift/Transport/StreamBuffer.php:265 Stack trace: #0 /home/content/88/10464488/html/demo/_lib/prod/third/swift/classes/Swift/Transport/StreamBuffer.php(66): Swift_Transport_StreamBuffer->_establishSocketConnection() #1 /home/content/88/10464488/html/demo/_lib/prod/third/swift/classes/Swift/Transport/AbstractSmtpTransport.php(117): Swift_Transport_StreamBuffer->initialize(Array) #2 /home/content/88/10464488/html/demo/_lib/prod/third/swift/classes/Swift/Mailer.php(79): Swift_Transport_AbstractSmtpTransport->start() #3 /home/content/88/10464488/html/demo/index/index_apl.php(887): Swift_Mailer->send(Object(Swift_Message), Array) #4 /home/content/88/10464488/html/demo/index/index_apl.php(924): index_apl->ini_controle() #5 /home/content/88/10464488/html/demo/index/index.php(1374): index_apl-> in /home/content/88/10464488/html/demo/_lib/prod/third/swift/classes/Swift/Transport/StreamBuffer.php on line 265

We have an msmtprc.ini in our uniserver. That one also needs to be edited.
Just check all ini files with the word smtp in it and edit it if needed.