Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8006645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:34:53+00:00 2026-06-04T17:34:53+00:00

I want to use Database mail for my application and this means I need

  • 0

I want to use Database mail for my application and this means I need to pass parameters to the stored procedure sp_send_dbmail
I have the following code just for testing purposes. I however want to know how to pass Parameters to a stored procedure using ssql server 2008 and php.
FYI I am using sqlsrv driver from Microsoft

<?php require_once ('../Connection/connmail.php')?> 
<?php
 $sql = "{CALL sp_send_dbmail[[@profile_name='gmailsmtp']]}";//my stored procedure

    $stmt = sqlsrv_query($conn,$sql)or die(print_r(sqlsrv_errors(),true));    


 ?> 

The above code produces the error

Array ( [0] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 102 [code] => 102 [2] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Incorrect syntax near '{'. [message] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Incorrect syntax near '{'. ) [1] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 105 [code] => 105 [2] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Unclosed quotation mark after the character string '[@profile_name='gmailsmtp']}'. [message] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Unclosed quotation mark after the character string '[@profile_name='gmailsmtp']}'. ) ) 

Any help will be appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T17:34:54+00:00Added an answer on June 4, 2026 at 5:34 pm

    I saw this was unanswered for a while so here is the solution. Make your user a databasemailuserrole in the msdb system database

    $callmailproc = "EXEC msdb.dbo.sp_send_dbmail @profile_name = ?, @recipients=?, @subject=?, @body=?";
    $profilename = 'DatabaseMail';
    $recipients = 'recipient@domain.com';
    $subject='Test Message';
    $body = 'This is the body';
    $params = array( 
                     array($profilename, SQLSRV_PARAM_IN),
                     array($recipients, SQLSRV_PARAM_IN),
                     array($subject, SQLSRV_PARAM_IN),
                     array($body, SQLSRV_PARAM_IN),
                     );
    
    /* Execute the query. */
    $stmt3 = sqlsrv_query( $conn, $callmailproc, $params);
    if( $stmt3 === false )
    {
         echo "Error in executing statement 3.\n";
         die( print_r( sqlsrv_errors(), true));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have information stored in a database that I want to use to create
Proviso: I don't want to use a database for the following, please. I'm getting
I have a string being returned from my database that I want to use
I want to use Access database with query for pivot table in Excel. How
First, I don't want to use a database or a local file. Is it
I want to use JDBC to access a MySQL database. What or will an
I want to use string similarity functions to find corrupted data in my database.
I created a new mysql database and i want to use foreign keys with
I'm in Asp.net MVC3 environment, and I use Advantage Database 9.1. and I want
I want to make custom select from the database table using Linq. We use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.